[Patches] [ python-Patches-604600 ] For Bug [ 490168 ] shutil.copy(path, pat

noreply@sourceforge.net noreply@sourceforge.net
Sun, 08 Sep 2002 13:46:25 -0700


Patches item #604600, was opened at 2002-09-04 11:21
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=604600&group_id=5470

Category: Library (Lib)
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Christos Georgiou (tzot)
Assigned to: Nobody/Anonymous (nobody)
Summary: For Bug [ 490168 ] shutil.copy(path, pat

Initial Comment:
As the bug says, shutil.copy(src, dst) deletes the
contents of src if it is the same as dst.  Example:
$ pwd
/home/tzot
$ echo hello >file01
$ ln file01 file02
$ echo hello >file03
$ ln -s file03 file04
$ echo hello >file05
$ python
Python 2.3a0 (#26, Sep  4 2002, 17:39:22) [C] on irix646
Type "help", "copyright", "credits" or "license" for
more information.
>>> from shutil import copyfile
>>> copyfile('file01', 'file02')
>>> copyfile('file03', 'file04')
>>> copyfile('file05', '../tzot/file05')

After this sequence, all files have zero length.
The patch corrects this.

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-09-08 15:46

Message:
Logged In: YES 
user_id=80475

Added a simplified version of the patch to Py2.3.
See shutil.py 1.23

Am leaving the Posix piece out for several reasons:
-- I'm on Windows and can't verify the code
-- As patched, the code didn't work at all (it assumed that 
the destination existed and the call to stat fails if it doesn't)
-- Handling symbolic links is a somewhat special case.

Thanks for the patch.  It's great that you helped address 
one of the older pending bugs.

For the future, please send a cvs diff -c taken from the 
current version of the file.  Please test all cases (when src 
and dst are the same, when the same but spelled 
differently, and when they are different altogether).  Also, 
please remove the print statements so the patch can be 
applied directly.  Also, please post the patches directly to 
the original bug instead of opening a separate patch -- this 
simplifies tracking the discussion.

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

Comment By: Christos Georgiou (tzot)
Date: 2002-09-08 09:20

Message:
Logged In: YES 
user_id=539787

This is a check that is true only on POSIX systems AFAIK.
On windows systems, st_ino is reported as 0 for all files, so 
the files would falsely be presumed to be the same file and 
therefore not copied.

PS At least on NTFS, files do have an inode number (same 
concept)... there is even a CreateHardLink call in kernel32.dll, 
which can be used to create hard links; MS implemented this 
since NT 3.51 I think, in order to attain POSIX conformability; 
however, either python ignores that, or MS do not provide 
information in their stat and / or link simulated system calls.  
I will invest some time in getting acquainted to Windows 
programming so that I research into this and offer a patch to 
posixmodule.c.
If interested, see http://msdn.microsoft.com/library/en-
us/fileio/base/createhardlink.asp

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-09-07 22:54

Message:
Logged In: YES 
user_id=80475

What is this line for?

  if _src.st_ino>0<_dst.st_ino 
----------------------------------------------------------------------

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