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

SourceForge.net noreply at sourceforge.net
Sat Aug 14 16:06:00 CEST 2004


Patches item #854853, was opened at 2003-12-05 17:33
Message generated for change (Settings changed) made by jlgijsbers
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: Closed
Resolution: Accepted
Priority: 5
Submitted By: Gregory H. Ball (greg_ball)
>Assigned to: Johannes Gijsbers (jlgijsbers)
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.


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

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-14 15:31

Message:
Logged In: YES 
user_id=469548

Checked in your revised patch as rev 1.31 of shutil.py and
rev 1.5 of test_shutil.py, with some modifications (notably,
not using a blank except: statement and using
test_support.TESTFN),

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

Comment By: Gregory H. Ball (greg_ball)
Date: 2004-07-14 21:11

Message:
Logged In: YES 
user_id=11365

I've revised the patch to make the test code more consistent
with what was already present.  I think this should be
accepted or rejected before python2.4 ships, as it is a good
complement to 
Bug #919012.



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

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