[meld] When copying symlinks, copy the link not the content (closes bgo#635883)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] When copying symlinks, copy the link not the content (closes bgo#635883)
- Date: Tue, 28 Dec 2010 23:36:43 +0000 (UTC)
commit b4c971900dc582cdf8036a106f2efbfdc4df899b
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Nov 27 11:56:44 2010 +1000
When copying symlinks, copy the link not the content (closes bgo#635883)
meld/misc.py | 28 +++++++++++++++++++++-------
1 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index d272df8..8f1460e 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -264,19 +264,34 @@ def commonprefix(dirs):
return os.sep.join(prefix)
def copy2(src, dst):
- """Like shutil.copy2 but ignores chmod errors.
+ """Like shutil.copy2 but ignores chmod errors, and copies symlinks as links
See [Bug 568000] Copying to NTFS fails
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
- shutil.copyfile(src, dst)
+
+ if os.path.islink(src) and os.path.isfile(src):
+ os.symlink(os.readlink(src), dst)
+ elif os.path.isfile(src):
+ shutil.copyfile(src, dst)
+ else:
+ raise OSError("Not a file")
+
try:
shutil.copystat(src, dst)
except OSError, e:
if e.errno != errno.EPERM:
raise
-def copytree(src, dst, symlinks=1):
+def copytree(src, dst):
+ """Similar to shutil.copytree, but always copies symlinks and doesn't
+ error out if the destination path already exists.
+ """
+ # If the source tree is a symlink, duplicate the link and we're done.
+ if os.path.islink(src):
+ os.symlink(os.readlink(src), dst)
+ return
+
try:
os.mkdir(dst)
except OSError, e:
@@ -286,11 +301,10 @@ def copytree(src, dst, symlinks=1):
for name in names:
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
- if symlinks and os.path.islink(srcname):
- linkto = os.readlink(srcname)
- os.symlink(linkto, dstname)
+ if os.path.islink(srcname):
+ os.symlink(os.readlink(srcname, dstname))
elif os.path.isdir(srcname):
- copytree(srcname, dstname, symlinks)
+ copytree(srcname, dstname)
else:
copy2(srcname, dstname)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]