[Patches] [ python-Patches-854853 ] shutil.copyfile destroys hard links (Bug [ 851123 ])

SourceForge.net noreply at sourceforge.net
Fri Dec 5 11:33:10 EST 2003


Patches item #854853, was opened at 2003-12-05 11:33
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=854853&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory H. Ball (greg_ball)
Assigned to: Nobody/Anonymous (nobody)
Summary: shutil.copyfile destroys hard links (Bug [ 851123 ])

Initial Comment:
shutil.copyfile(src,dst) will destroy src if dst is a
hard or symbolic link to src.  (This is bug [851123].)

There was a version of patch [ 604600 ] For Bug [
490168 ] which sought to address this problem but it
wasn't implemented properly.

My patch checks for the existence of
os.path.samefile(), (which on posix systems follows
symlinks) and uses that as a guard if available.  It
catches the exception raised by samefile() if dst does
not exist.  (It also catches the exception raised if
src does not exist, but this doesn't matter since that
condition will cause a new exception in the next part
of the code.)

I have included test code, which tests for the bug only
if os.symlink exists.  If there is a platform with
symlink but not samefile, the test will fail; I think
that would indicate more fixing of shutil.py is required.
I avoided using tempfile.mktemp to a degree since that
function is now deprecated.  I made a judgement call
that calling mktemp with a private temp dir (from
mkdtemp) is safe. Perhaps in a private temp dir we can
just use a hard-coded filename, if mktemp is really
despised.

Since this is just a bugfix I included no doc updates.


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

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



More information about the Patches mailing list