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.move(): Add ability to use custom copy function to allow to ignore metadata
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, Claudiu.Popa, desbma, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2013-11-30 13:05 by desbma, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
shutil.patch Claudiu.Popa, 2013-12-01 08:48 review
issue19840.patch Claudiu.Popa, 2014-03-16 20:19 Fix trailing whitespaces. review
issue19840_1.patch Claudiu.Popa, 2014-06-10 15:21 review
Messages (8)
msg204807 - (view) Author: desbma (desbma) * Date: 2013-11-30 13:05
shutil.move sometimes fail when the underlining filesystem has limitations.

Here is a part of a stacktrace I'm getting :

  File "/usr/local/lib/python3.3/shutil.py", line 534, in move
    copy2(src, real_dst)
  File "/usr/local/lib/python3.3/shutil.py", line 244, in copy2
    copystat(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/local/lib/python3.3/shutil.py", line 192, in copystat
    lookup("chmod")(dst, mode, follow_symlinks=follow)
OSError: [Errno 38]

This behaviour is expected because shutil.move uses shutil.copy2 under the hood to copy file data and metadata.

However there is no way to tell shutil.move to use shutil.copy and to ignore metadata.

Maybe a new copy_metadata parameter (defaulting to True) or copy_function (like in shutil.copytree) would be an elegant solution?
msg204835 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-30 18:52
Note that the equivalent linux command generates a warning message but does the move anyway.  In other words, this seems like a very reasonable request ;)
msg204891 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2013-12-01 08:48
Hi. Here's a patch which adds `copy_function` parameter to `shutil.move`.
msg220142 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-06-10 06:56
Any type of feedback will be appreciated.
msg220166 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-10 13:43
Review comments added.  Patch looks good after the doc fixes.  We also need a whatsnew entry.
msg220170 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-06-10 15:21
Thanks, David. The new version of the patch is attached.
msg220296 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-06-11 18:40
New changeset 0d61a2a50f9f by R David Murray in branch 'default':
#19840: Add copy_function to shutil.move.
http://hg.python.org/cpython/rev/0d61a2a50f9f
msg220297 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-11 18:41
Thanks, Claudiu.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64039
2014-06-11 18:41:21r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg220297

stage: resolved
2014-06-11 18:40:27python-devsetnosy: + python-dev
messages: + msg220296
2014-06-10 18:53:31Arfreversettitle: The is no way to tell shutil.move to ignore metadata -> shutil.move(): Add ability to use custom copy function to allow to ignore metadata
2014-06-10 15:21:25Claudiu.Popasetfiles: + issue19840_1.patch

messages: + msg220170
2014-06-10 13:43:02r.david.murraysetmessages: + msg220166
2014-06-10 06:56:05Claudiu.Popasetmessages: + msg220142
2014-03-16 20:19:30Claudiu.Popasetfiles: + issue19840.patch
2013-12-01 08:48:10Claudiu.Popasetfiles: + shutil.patch
keywords: + patch
messages: + msg204891
2013-12-01 08:35:54Claudiu.Popasetnosy: + Claudiu.Popa
2013-12-01 08:06:41Arfreversetnosy: + Arfrever
2013-11-30 18:52:41r.david.murraysetversions: + Python 3.5, - Python 3.3
2013-11-30 18:52:08r.david.murraysetnosy: + r.david.murray
messages: + msg204835
2013-11-30 13:05:40desbmacreate