[New-bugs-announce] [issue8125] shutil.copytree behavior is inconsistent with copyfile
joseph.h.garvin
report at bugs.python.org
Fri Mar 12 17:25:07 CET 2010
New submission from joseph.h.garvin <joseph.h.garvin at gmail.com>:
shutil.copyfile's behavior is to replace the dst file if it already exists. shutil.copytree requires that the destination not already exist, and throws an OSError if it does. I see 3 problems with this behavior:
1. It's inconsistent with copyfile
2. It's inconsistent with 'cp', which is what users would be using if they were writing shell script. Given shutil's namesake I assume it's supposed to help make python a viable shell script replacement.
3. It makes it difficult to use copytree with tempfile.mkdtemp(). If I want to make a temporary directory and copy a folder into it, I need to copytree to a nonexist subfolder then move all the files down a level or resort to other unpythonic hacks. In my project I copy unit test resources to a temp folder because they're manipulated throughout the test and I want to keep the originals. I imagine that this is a common use case.
That said, if anyone depended on shutil.copytree failing to test whether or not a folder exists, changing this would break compatibility, so if it can't be changed, maybe a shutil.mergetree would be appropriate.
----------
components: Library (Lib)
messages: 100943
nosy: joseph.h.garvin
severity: normal
status: open
title: shutil.copytree behavior is inconsistent with copyfile
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8125>
_______________________________________
More information about the New-bugs-announce
mailing list