diff options
author | Laurent Bachelier <laurent@bachelier.name> | 2010-01-06 01:26:28 +0100 |
---|---|---|
committer | Laurent Bachelier <laurent@bachelier.name> | 2010-01-06 01:29:08 +0100 |
commit | a4be2683bdc7d2f4005835055e1e2676cd8f0457 (patch) | |
tree | 5370a11a1f572b83371224c49f355d500b592d45 | |
parent | Released under the MIT license (diff) | |
download | confman-a4be2683bdc7d2f4005835055e1e2676cd8f0457.tar.xz |
Symlink creation enhancements
* Works with non-absolute sources and destinations
* Does not crash when an old link is broken
-rw-r--r-- | confman.py | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -54,8 +54,11 @@ class SymlinkConfigAction(ConfigAction): source = self.source_path() dest = self.dest_path() if os.path.lexists(dest): + # if the link already exists if os.path.islink(dest): - if not os.path.samefile(dest, source): + # if the old link is broken or incorrect + if not os.path.exists(dest) \ + or not os.path.samefile(dest, source): os.unlink(dest) print "Link target altered" else: @@ -63,8 +66,9 @@ class SymlinkConfigAction(ConfigAction): else: self._makedirs() + relsource = os.path.relpath(source, self.config.dest) + os.symlink(relsource, dest) print "Created new link: "+dest+" => "+source - os.symlink(source, dest) class CopyConfigAction(ConfigAction): |