diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-10-07 10:49:58 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-10-07 10:49:58 (GMT) |
commit | 4865376c4457ffc2f76a34bcc29b620c1ea0bcea (patch) | |
tree | d7560cab03a387d26c2906a74d6172d695077041 /Lib/shutil.py | |
parent | 09c61bef2d406bac2ea031a6b50d841ee6cf678b (diff) | |
download | cpython-4865376c4457ffc2f76a34bcc29b620c1ea0bcea.zip cpython-4865376c4457ffc2f76a34bcc29b620c1ea0bcea.tar.gz cpython-4865376c4457ffc2f76a34bcc29b620c1ea0bcea.tar.bz2 |
Closes #1492704: Make shutil.copyfile() raise a distinct SameFileError
Patch by Atsuo Ishimoto.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 5dc311e..27239f6 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -42,6 +42,9 @@ __all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2", class Error(EnvironmentError): pass +class SameFileError(Error): + """Raised when source and destination are the same file.""" + 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_symlinks=True): """ if _samefile(src, dst): - raise Error("`%s` and `%s` are the same file" % (src, dst)) + raise SameFileError("{!r} and {!r} are the same file".format(src, dst)) for fn in [src, dst]: try: @@ -215,6 +218,9 @@ def copy(src, dst, *, follow_symlinks=True): If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst". + If source and destination are the same file, a SameFileError will be + raised. + """ if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src)) |