summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-09-07 21:09:07 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-09-07 21:09:07 +0000
commita1f7a568112f61daaa9b2ac9903419f2d4718c40 (patch)
tree6bc575b208ede205fbdc085020726c8fad337959 /src
parent5a374b8be640be6baf1b435499596999bedec1f8 (diff)
downloadbcfg2-a1f7a568112f61daaa9b2ac9903419f2d4718c40.tar.gz
bcfg2-a1f7a568112f61daaa9b2ac9903419f2d4718c40.tar.bz2
bcfg2-a1f7a568112f61daaa9b2ac9903419f2d4718c40.zip
POSIX: Add hard link support for ticket #588
Add support for HardLink entries using the new unified POSIX interface. Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5417 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Client/Tools/POSIX.py52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index 37a4111d4..610305a09 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -82,8 +82,9 @@ class POSIX(Bcfg2.Client.Tools.Tool):
__handles__ = [('ConfigFile', None), ('ConfigFile', 'Compat'),
('Directory', None), ('Path', 'ConfigFile'),
('Path', 'Device'), ('Path', 'Directory'),
- ('Path', 'Perms'), ('Path', 'SymLink'),
- ('Permissions', None), ('SymLink', None)]
+ ('Path', 'HardLink'), ('Path', 'Perms'),
+ ('Path', 'SymLink'), ('Permissions', None),
+ ('SymLink', None)]
__req__ = {'ConfigFile': ['name', 'owner', 'group', 'perms'],
'Directory': ['name', 'owner', 'group', 'perms'],
'Path': ['name', 'type'],
@@ -142,9 +143,6 @@ class POSIX(Bcfg2.Client.Tools.Tool):
self.cmd.run("mv %s/ %s.bak" % \
(entry.get('name'),
entry.get('name')))
- elif S_ISLNK(fmode):
- self.logger.debug("Replacing existing SymLink with the one "
- "specified in bcfg2")
else:
os.unlink(entry.get('name'))
except OSError:
@@ -320,6 +318,50 @@ class POSIX(Bcfg2.Client.Tools.Tool):
return False
return self.InstallPermissions(entry)
+ def VerifyHardLink(self, entry, _):
+ '''Verify HardLink Entry'''
+ try:
+ if os.path.samefile(entry.get('name'), entry.get('to')):
+ return True
+ self.logger.debug("Hardlink %s is incorrect" % \
+ entry.get('name'))
+ entry.set('qtext', "Link %s to %s? [y/N] " % \
+ (entry.get('name'),
+ entry.get('to')))
+ return False
+ except OSError:
+ entry.set('current_exists', 'false')
+ entry.set('qtext', "Link %s to %s? [y/N] " % \
+ (entry.get('name'),
+ entry.get('to')))
+ return False
+
+ def InstallHardLink(self, entry):
+ '''Install HardLink Entry'''
+ self.logger.info("Installing Hardlink %s" % (entry.get('name')))
+ if os.path.lexists(entry.get('name')):
+ try:
+ fmode = os.lstat(entry.get('name'))[ST_MODE]
+ if S_ISREG(fmode) or S_ISLNK(fmode):
+ self.logger.debug("Non-directory entry already exists at "
+ "%s. Unlinking entry." % (entry.get('name')))
+ os.unlink(entry.get('name'))
+ elif S_ISDIR(fmode):
+ self.logger.debug("Directory entry already exists at %s" % \
+ (entry.get('name')))
+ self.cmd.run("mv %s/ %s.bak" % \
+ (entry.get('name'),
+ entry.get('name')))
+ else:
+ os.unlink(entry.get('name'))
+ except OSError:
+ self.logger.info("Hardlink %s cleanup failed" % (entry.get('name')))
+ try:
+ os.link(entry.get('to'), entry.get('name'))
+ return True
+ except OSError:
+ return False
+
def VerifyPermissions(self, entry, _):
'''Verify Permissions entry'''
return self.VerifyDirectory(entry, _)