aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-01-06 01:26:28 +0100
committerLaurent Bachelier <laurent@bachelier.name>2010-01-06 01:29:08 +0100
commita4be2683bdc7d2f4005835055e1e2676cd8f0457 (patch)
tree5370a11a1f572b83371224c49f355d500b592d45
parentReleased under the MIT license (diff)
downloadconfman-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.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/confman.py b/confman.py
index ba241d3..649fa6c 100644
--- a/confman.py
+++ b/confman.py
@@ -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):