[ python-Bugs-1048878 ] shutil.copytree copies stat of files, but not of dirs

SourceForge.net noreply at sourceforge.net
Mon Oct 18 00:12:52 CEST 2004


Bugs item #1048878, was opened at 2004-10-18 00:12
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1048878&group_id=5470

Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Waldmann (thomaswaldmann)
Assigned to: Nobody/Anonymous (nobody)
Summary: shutil.copytree copies stat of files, but not of dirs

Initial Comment:
Caring for stat of files, but modifying stat of dirs is
maybe not what's expected from that function.

I discovered that when implementing a new function in
MoinMoin when it changed directory modes from
-rw-rw---- to -rw-------.

It is easy to fix:

$ diff -u shutil.py shutil.py-tw 
--- shutil.py   2004-10-17 23:19:25.000000000 +0200
+++ shutil.py-tw        2004-10-18 00:01:57.000000000 +0200
@@ -109,6 +109,7 @@
     """
     names = os.listdir(src)
     os.mkdir(dst)
+    copystat(src, dst)
     errors = []
     for name in names:
         srcname = os.path.join(src, name)

Maybe it is even better to do that copystat after the
for loop (and thus, after the recursive calls modifying
the timestamp of the directory) and before the if
statement, so it may even conserve the dir timestamp (I
didn't test that).

It happens in 2.3.4 as well as in 2.4 beta 1.

Strictly taken, it is not a bug, as the docs say
nothing about what it does to directories. But well,
maybe just the docs need to be changed as well. :)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1048878&group_id=5470


More information about the Python-bugs-list mailing list