about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2015-02-06 20:42:38 +0100
committerhut <hut@lepus.uberspace.de>2015-02-06 23:30:49 +0100
commit9495f9779c0604996cead68f2e083dbea4928b3c (patch)
treeb593de84c116eb6e402af49cdc77358eaab2ee95
parent1bb7f23f5474d7fa3ca535607e437d0622698de7 (diff)
downloadranger-9495f9779c0604996cead68f2e083dbea4928b3c.tar.gz
ext.shutil_generatorized: fixed #143 (copying of links)
This bug was introduced in a986e2bd...
-rw-r--r--ranger/ext/shutil_generatorized.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py
index 38e506a2..2df04926 100644
--- a/ranger/ext/shutil_generatorized.py
+++ b/ranger/ext/shutil_generatorized.py
@@ -103,6 +103,8 @@ def copy2(src, dst, overwrite=False, symlinks=False):
         dst = get_safe_path(dst)
     if symlinks and os.path.islink(src):
         linkto = os.readlink(src)
+        if overwrite and os.path.lexists(dst):
+            os.unlink(dst)
         os.symlink(linkto, dst)
     else:
         for _ in copyfile(src, dst):
@@ -171,11 +173,10 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False):
         try:
             if symlinks and os.path.islink(srcname):
                 linkto = os.readlink(srcname)
-                if os.path.lexists(dstname):
-                    if not os.path.islink(dstname) \
-                    or os.readlink(dstname) != linkto:
-                        os.unlink(dstname)
-                        os.symlink(linkto, dstname)
+                if overwrite and os.path.lexists(dstname):
+                    os.unlink(dstname)
+                os.symlink(linkto, dstname)
+                copystat(srcname, dstname)
             elif os.path.isdir(srcname):
                 for _ in copytree(srcname, dstname, symlinks,
                         ignore, overwrite):