From a4be2683bdc7d2f4005835055e1e2676cd8f0457 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Wed, 6 Jan 2010 01:26:28 +0100 Subject: Symlink creation enhancements * Works with non-absolute sources and destinations * Does not crash when an old link is broken --- confman.py | 8 ++++++-- 1 file 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): -- cgit v1.2.3