cpython: e11642068f85 (original) (raw)

Mercurial > cpython

changeset 79566:e11642068f85

Closes #1492704: Make shutil.copyfile() raise a distinct SameFileError Patch by Atsuo Ishimoto. [#1492704]

Hynek Schlawack hs@ox.cx
date Sun, 07 Oct 2012 12:49:58 +0200
parents 21a33257c744
children 73a9a8080594
files Doc/library/shutil.rst Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS
diffstat 4 files changed, 35 insertions(+), 5 deletions(-)[+] [-] Doc/library/shutil.rst 14 Lib/shutil.py 8 Lib/test/test_shutil.py 15 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -53,7 +53,7 @@ Directory and files operations dst and return dst. src and dst are path names given as strings. dst must be the complete target file name; look at :func:shutil.copy for a copy that accepts a target directory path. If src and dst

+ + +.. exception:: SameFileError +

+ .. function:: copymode(src, dst, *, follow_symlinks=True) Copy the permission bits from src to dst. The file contents, owner, and

--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -42,6 +42,9 @@ except ImportError: class Error(EnvironmentError): pass +class SameFileError(Error):

+ class SpecialFileError(EnvironmentError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" @@ -90,7 +93,7 @@ def copyfile(src, dst, *, follow_symlink """ if _samefile(src, dst):

for fn in [src, dst]: try: @@ -215,6 +218,9 @@ def copy(src, dst, *, follow_symlinks=Tr If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst".

+ """ if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src))

--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -18,7 +18,8 @@ from shutil import (_make_tarball, _make register_archive_format, unregister_archive_format, get_archive_formats, Error, unpack_archive, register_unpack_format, RegistryError,

import tarfile import warnings @@ -688,7 +689,7 @@ class TestShutil(unittest.TestCase): with open(src, 'w') as f: f.write('cheddar') os.link(src, dst)

@@ -708,7 +709,7 @@ class TestShutil(unittest.TestCase): # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. os.symlink('cheese', dst)

@@ -1215,6 +1216,14 @@ class TestShutil(unittest.TestCase): self.assertTrue(os.path.exists(rv)) self.assertEqual(read_file(src_file), read_file(dst_file))

+ def test_copytree_return_value(self): # copytree returns its destination path. src_dir = self.mkdtemp()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -39,6 +39,9 @@ Core and Builtins Library ------- +- Issue #1492704: shutil.copyfile() raises a distinct SameFileError now if