commit:     727d8118db98549b0cc48f3c56db842cf82b0c27
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 25 15:44:40 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Jun 25 15:44:40 2016 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=727d8118

fileops.py: Fix a traceback clearing teh old profile link

The isdir() cconditional was not enough, it also needed to make sure it was not 
a symlink.

25 Jun 2016 08:02:45 PDT: NOTICE  : --- Running action sequence: 
config_profile_link
25 Jun 2016 08:02:45 PDT: ERROR   : clear_dir failed
Traceback (most recent call last):
  File "/home/brian/Dev/git/catalyst/catalyst/fileops.py", line 84, in clear_dir
    shutil.rmtree(target)
  File "/usr/lib64/python3.4/shutil.py", line 478, in rmtree
    onerror(os.path.islink, path, sys.exc_info())
  File "/usr/lib64/python3.4/shutil.py", line 476, in rmtree
    raise OSError("Cannot call rmtree on a symbolic link")
OSError: Cannot call rmtree on a symbolic link

 catalyst/fileops.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 6971911..d2bd453 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -70,7 +70,7 @@ def clear_dir(target, mode=0o755, chg_flags=False, 
remove=False,
                return False
 
        mystat = None
-       if os.path.isdir(target):
+       if os.path.isdir(target) and not os.path.islink(target):
                log.info('Emptying directory: %s', target)
                # stat the dir, delete the dir, recreate the dir and set
                # the proper perms and ownership
@@ -87,6 +87,7 @@ def clear_dir(target, mode=0o755, chg_flags=False, 
remove=False,
                        return False
        elif os.path.exists(target):
                if clear_nondir:
+                       log.debug("Clearing (unlinking) non-directory: %s", 
target)
                        os.unlink(target)
                else:
                        log.info('clear_dir failed: %s: is not a directory', 
target)

Reply via email to