This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.copy(path, path) deletes contents
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, mattkirst, mwh, rhettinger, tzot
Priority: normal Keywords:

Created on 2001-12-07 09:16 by anonymous, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (6)
msg8055 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-12-07 09:16
If source equals destination path the contents of the 
file is deleted.
msg8056 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-12-08 17:17
Logged In: YES 
user_id=6380

I know the Unix 'cp' command tests for this condition, but
shouldn't this fall in the category of "don't do that, then"
in the Python world? How stupid do we expect the programmer
to be?
msg8057 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2001-12-10 10:42
Logged In: YES 
user_id=6656

To the OP, if you're paying attention: shutil is pretty
useless.  You might consider using distutils.file_util
instead (though I don't know if that suffers from this
"problem").

I wanted to do somthing about this before 2.2, sigh...
msg8058 - (view) Author: Matthias Kirst (mattkirst) Date: 2001-12-10 11:06
Logged In: YES 
user_id=397984

That's correct when using the command interactively. 
But when the command is used in an environment where source 
and destination path come from user interactions over a GUI 
for instance the programmer won't check for the source and 
destination path each time the command is called. 
In my example I had a relative and an absolute path to 
compare. So I would have had the relative path tracked 
programmatically. At the end it seemed clearer to me to 
read the source file out, create an empty destination 
(open "w+") and write the dump to this file. 
msg8059 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2002-09-04 16:22
Logged In: YES 
user_id=539787

See patch 604600
msg8060 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-09-08 20:50
Logged In: YES 
user_id=80475

Fixed for Py2.3.
See shutil.py 1.23
Also, see patch 604600.
History
Date User Action Args
2022-04-10 16:04:44adminsetgithub: 35686
2001-12-07 09:16:49anonymouscreate