From f8a6863ba54f9e97a47fba1526fbc6508059ba18 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Wed, 29 Mar 2006 16:21:36 +0000 Subject: * Fix parent directory creation for directory entries (resolving Ticket #37) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1813 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Toolset.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/lib/Client/Toolset.py') diff --git a/src/lib/Client/Toolset.py b/src/lib/Client/Toolset.py index 470395d5a..9e5c8c97a 100644 --- a/src/lib/Client/Toolset.py +++ b/src/lib/Client/Toolset.py @@ -305,6 +305,28 @@ class Toolset(object): exists = False if not exists: + parent = "/".join(entry.get('name').split('/')[:-1]) + if parent: + try: + os.lstat(parent) + except: + self.logger.debug('Creating parent path for directory %s' % (entry.get('name'))) + for idx in xrange(len(parent.split('/')[:-1])): + current = '/'+'/'.join(parent.split('/')[1:2+idx]) + try: + sloc = os.lstat(current) + try: + if not S_ISDIR(sloc[ST_MODE]): + os.unlink(current) + os.mkdir(current) + except OSError: + return False + except OSError: + try: + os.mkdir(current) + except OSError: + return False + try: os.mkdir(entry.get('name')) except OSError: -- cgit v1.2.3-1-g7c22