summaryrefslogtreecommitdiffstats
path: root/src/lib/Client
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-02-21 13:34:58 -0600
committerSol Jerome <sol.jerome@gmail.com>2011-02-21 13:34:58 -0600
commitcebc13ad35a2c63ba7cf1374d60a32beaa01f275 (patch)
tree6ed45144e6d9420965f7395b96f6c58f248b2131 /src/lib/Client
parent1e0c946bb6e6aea51d8fad808ea6638c603c7382 (diff)
downloadbcfg2-cebc13ad35a2c63ba7cf1374d60a32beaa01f275.tar.gz
bcfg2-cebc13ad35a2c63ba7cf1374d60a32beaa01f275.tar.bz2
bcfg2-cebc13ad35a2c63ba7cf1374d60a32beaa01f275.zip
POSIX: Implement recursive attribute for nonexistent Paths
The POSIX client tool now has the ability to recursively remove the contents of a specified directory provided there are no other managed entries under the directory. Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Client')
-rw-r--r--src/lib/Client/Tools/POSIX.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index d2611130c..c883fc17a 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -671,12 +671,36 @@ class POSIX(Bcfg2.Client.Tools.Tool):
def Installnonexistent(self, entry):
'''Remove nonexistent entries'''
- try:
- os.remove(entry.get('name'))
- return True
- except OSError:
- self.logger.error('Failed to remove %s' % entry.get('name'))
- return False
+ ename = entry.get('name')
+ if entry.get('recursive') in ['True', 'true']:
+ # ensure that configuration spec is consistent first
+ if [e for e in self.buildModlist() \
+ if e.startswith(ename) and e != ename]:
+ self.logger.error('Not installing %s. One or more files '
+ 'in this directory are specified in '
+ 'your configuration.' % ename)
+ return False
+ try:
+ shutil.rmtree(ename)
+ except OSError, e:
+ self.logger.error('Failed to remove %s: %s' % (ename,
+ e.strerror))
+ else:
+ if os.path.isdir(ename):
+ try:
+ os.rmdir(ename)
+ return True
+ except OSError, e:
+ self.logger.error('Failed to remove %s: %s' % (ename,
+ e.strerror))
+ return False
+ try:
+ os.remove(ename)
+ return True
+ except OSError, e:
+ self.logger.error('Failed to remove %s: %s' % (ename,
+ e.strerror))
+ return False
def Verifypermissions(self, entry, _):
"""Verify Path type='permissions' entry"""