summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-10-02 19:55:20 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-10-02 19:55:20 +0000
commit46707594044bc6c84264ed45c70d9a40dbe0f011 (patch)
treef0ffcb64252395d9cf4ac1049a07d1d2ba78caa8 /src/lib
parent2d095a5b31d4485673693aa676bd01a53e1033f5 (diff)
downloadbcfg2-46707594044bc6c84264ed45c70d9a40dbe0f011.tar.gz
bcfg2-46707594044bc6c84264ed45c70d9a40dbe0f011.tar.bz2
bcfg2-46707594044bc6c84264ed45c70d9a40dbe0f011.zip
Implement prune mode for directories (only bundle entries are allowed in the directory)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3772 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Client/Tools/POSIX.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index ff3492302..7b0544a25 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -116,7 +116,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
except OSError:
return False
- def VerifyDirectory(self, entry, _):
+ def VerifyDirectory(self, entry, modlist):
'''Verify Directory Entry'''
while len(entry.get('perms', '')) < 4:
entry.set('perms', '0' + entry.get('perms', ''))
@@ -140,12 +140,32 @@ class POSIX(Bcfg2.Client.Tools.Tool):
mtime = str(finfo[ST_MTIME])
else:
mtime = '-1'
- if ((owner == str(normUid(entry))) and
- (group == str(normGid(entry))) and
- (perms == entry.get('perms')) and
- (mtime == entry.get('mtime', '-1'))):
- return True
+ pTrue = ((owner == str(normUid(entry))) and
+ (group == str(normGid(entry))) and
+ (perms == entry.get('perms')) and
+ (mtime == entry.get('mtime', '-1')))
+
+ pruneTrue = True
+ if entry.get('prune', 'false') == 'true' \
+ and entry.tag == 'Directory':
+ try:
+ entries = ['/'.join([entry.get('name'), ent]) \
+ for ent in os.listdir(entry.get('name'))]
+ self.ex_ents = [e for e in entries if e not in modlist]
+ if self.ex_ents:
+ pruneTrue = False
+ self.logger.debug("Directory %s contains extra entries:" % entry.get('name'))
+ self.logger.debug(self.ex_ents)
+ nqtext = entry.get('qtext', '') + '\n'
+ nqtext += "Directory %s contains extra entries:" % entry.get('name')
+ nqtext += ":".join(self.ex_ents)
+ entry.set('qtest', nqtext)
+ except OSError:
+ pruneTrue = True
else:
+ pruneTrue = True
+
+ if not pTrue:
if owner != str(normUid(entry)):
entry.set('current_owner', owner)
self.logger.debug("%s %s ownership wrong" % (entry.tag, entry.get('name')))
@@ -181,7 +201,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
nnqtext = entry.get('qtext')
nnqtext += '\nInstall %s %s: (y/N) ' % (entry.tag, entry.get('name'))
entry.set('qtext', nnqtext)
- return False
+ return pTrue and pruneTrue
+
def InstallDirectory(self, entry):
'''Install Directory Entry'''
@@ -230,6 +251,17 @@ class POSIX(Bcfg2.Client.Tools.Tool):
except OSError:
self.logger.error('Failed to create directory %s' % (entry.get('name')))
return False
+ if entry.get('prune', 'false') == 'true' and self.ex_ents:
+ for pname in self.ex_ents:
+ ulfailed = False
+ try:
+ self.logger.debug("Unlinking file %s" % pname)
+ os.unlink(pname)
+ except OSError:
+ self.logger.error("Failed to unlink path %s" % pname)
+ ulfailed = True
+ if ulfailed:
+ return False
return self.InstallPermissions(entry)
def VerifyPermissions(self, entry, _):