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

noreply@sourceforge.net noreply@sourceforge.net
Sun, 08 Sep 2002 07:20:15 -0700


Patches item #604600, was opened at 2002-09-04 19: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: Open
Resolution: None
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: Christos Georgiou (tzot)
Date: 2002-09-08 17: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-08 06: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