diff options
author | devcurmudgeon <paul.sherwood@codethink.co.uk> | 2017-02-18 12:41:03 +0000 |
---|---|---|
committer | devcurmudgeon <paul.sherwood@codethink.co.uk> | 2017-02-18 12:41:03 +0000 |
commit | 4a44598abdb8ba83bf2ee9099b2a69ac645ee94e (patch) | |
tree | 19716ebe05ef9e53f295c2cce9d016d8577b7bdd | |
parent | 078581743969c7a98f453a115394a8dd7f876bb2 (diff) | |
parent | 3a52e4956a7be053c492990b035f0eead925b273 (diff) | |
download | ybd-4a44598abdb8ba83bf2ee9099b2a69ac645ee94e.tar.gz |
Merge branch 'tristan/symlinks' into 'master'
utils.py: Dont stomp on non-empty directories with symlinks
See merge request !305
-rw-r--r-- | ybd/utils.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/ybd/utils.py b/ybd/utils.py index e9344fb..975d8ae 100644 --- a/ybd/utils.py +++ b/ybd/utils.py @@ -20,6 +20,7 @@ import contextlib import os import shutil import stat +import errno from fs.osfs import OSFS from fs.multifs import MultiFS import calendar @@ -155,13 +156,23 @@ def _process_tree(root, srcpath, destpath, actionfunc): path = re.search('/.*$', re.search('tmp[^/]+/.*$', destpath).group(0)).group(0) app.config['new-overlaps'] += [path] + + # Try to remove anything that is in the way, but issue + # a warning instead if it removes a non empty directory try: os.unlink(destpath) - except: + except OSError as e: + if e.errno != errno.EISDIR: + raise + try: - os.remove(destpath) - except: - shutil.rmtree(destpath) + os.rmdir(destpath) + except OSError as e: + if e.errno == errno.ENOTEMPTY: + app.log('UTILS', + 'WARNING: Ignoring symlink "' + destpath + + '" which purges non-empty directory') + return # Ensure that the symlink target is a relative path target = os.readlink(srcpath) |