From cebc13ad35a2c63ba7cf1374d60a32beaa01f275 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Mon, 21 Feb 2011 13:34:58 -0600 Subject: 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 --- src/lib/Client/Tools/POSIX.py | 36 ++++++++++++++++++++++++++++++------ src/sbin/bcfg2-repo-validate | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src') 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""" diff --git a/src/sbin/bcfg2-repo-validate b/src/sbin/bcfg2-repo-validate index 3d5efb093..554e4f72b 100755 --- a/src/sbin/bcfg2-repo-validate +++ b/src/sbin/bcfg2-repo-validate @@ -94,7 +94,7 @@ if __name__ == '__main__': 'hardlink': ['name', 'to'], 'symlink': ['name', 'to'], 'ignore': ['name'], - 'nonexist': ['name'], + 'nonexistent': ['name'], 'permissions': ['name', 'owner', 'group', 'perms']} for rfile in rules_list: try: -- cgit v1.2.3-1-g7c22