]> granicus.if.org Git - python/commitdiff
Don't copy directory stat times in shutil.copytree on Windows
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 30 Jul 2006 13:00:31 +0000 (13:00 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 30 Jul 2006 13:00:31 +0000 (13:00 +0000)
Fixes #1525866.

Lib/shutil.py
Lib/test/test_shutil.py
Misc/NEWS

index c50184c733cf3e413cec3f663bc115456c774701..c3ff687bff4efcd407f16cddbf71995f7d8962b2 100644 (file)
@@ -127,7 +127,13 @@ def copytree(src, dst, symlinks=False):
         # continue with other files
         except Error, err:
             errors.extend(err.args[0])
-    copystat(src, dst)
+    try:
+        copystat(src, dst)
+    except WindowsError:
+        # can't copy file access times on Windows
+        pass
+    except OSError, why:
+        errors.extend((src, dst, str(why)))
     if errors:
         raise Error, errors
 
index 6ab5a35ef963ea2c049fd98b8ec03f76333c10df..79da53814d10db4bef3b12246dc772503fab438d 100644 (file)
@@ -74,6 +74,33 @@ class TestShutil(unittest.TestCase):
             except:
                 pass
 
+                
+    def test_copytree_simple(self):
+        src_dir = tempfile.mkdtemp()
+        dst_dir = os.path.join(tempfile.mkdtemp(), 'destination')
+        open(os.path.join(src_dir, 'test.txt'), 'w').write('123')
+        os.mkdir(os.path.join(src_dir, 'test_dir'))
+        open(os.path.join(src_dir, 'test_dir', 'test.txt'), 'w').write('456')
+        #
+        try:
+            shutil.copytree(src_dir, dst_dir)
+            self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
+            self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
+            self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir', 'test.txt')))
+            self.assertEqual(open(os.path.join(dst_dir, 'test.txt')).read(), '123')
+            self.assertEqual(open(os.path.join(dst_dir, 'test_dir', 'test.txt')).read(), '456')
+        finally:
+            try:
+                os.remove(os.path.join(src_dir, 'test.txt'))
+                os.remove(os.path.join(dst_dir, 'test.txt'))
+                os.remove(os.path.join(src_dir, 'test_dir', 'test.txt'))
+                os.remove(os.path.join(dst_dir, 'test_dir', 'test.txt'))
+                os.removedirs(src_dir)
+                os.removedirs(dst_dir)
+            except:
+                pass
+            
+            
     if hasattr(os, "symlink"):
         def test_dont_copy_file_onto_link_to_itself(self):
             # bug 851123.
index ca5f5c8d9f07aec07e8b5b27f5a3d08c86184e8a..dec5a2c0d570143180e1fcf79f13bf0dee753d59 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -61,6 +61,9 @@ Core and builtins
 Library
 -------
 
+- Bug #1525866: Don't copy directory stat times in 
+  shutil.copytree on Windows
+
 - Bug #1002398: The documentation for os.path.sameopenfile now correctly
   refers to file descriptors, not file objects.