]> granicus.if.org Git - python/commitdiff
shutil.copyfile(src,dst) was clobbering the file when the src and dst were
authorRaymond Hettinger <python@rcn.com>
Sun, 8 Sep 2002 20:43:59 +0000 (20:43 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 8 Sep 2002 20:43:59 +0000 (20:43 +0000)
the same.   Added check to verify the two names are not the same.  Does not
check the actual files to see if there is a symbolic link.

Closes SF bug 490165 and Tzot's patch 604600.

Lib/shutil.py

index 3076be92e167cb2edb293bcb904c96421ddc3e20..0e60870957cc6f1bce8c4abaa644cbdae5d6bc99 100644 (file)
@@ -24,6 +24,11 @@ def copyfile(src, dst):
     """Copy data from src to dst"""
     fsrc = None
     fdst = None
+    # check for same pathname; all platforms
+    _src = os.path.normcase(os.path.abspath(src))
+    _dst = os.path.normcase(os.path.abspath(dst))
+    if _src == _dst:
+        return
     try:
         fsrc = open(src, 'rb')
         fdst = open(dst, 'wb')