-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-42948: Fix shutil.move() on permission-restricted filesystems #141697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
gpshead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As is, this also changes the default behavior of copy2 - and thus move and copytree which default to using copy2 - to not fail if the file times could not be set.
While it is arguable that the new behavior is what people might expect, raising the error in this situation has been the API for so long, we should assume someone is relying on that. (Hyrum's Law)
I think we should err on the side of caution and retain backwards compatibility but provide a way to get the error-free behavior.
At a minimum, add a keyword only argument to copystat to determine if utime permission errors should raise or not. Plumb that through into copy2 as well.
We could do a little more plumbing through to, move, and copytree - but that proliferation of arguments can get a bit gross. I suggest we just add to their docs that users who want to ignore inability to set the utime can do so via a copy_function.
With an example in Docs of passing copy_function=lambda s, d: shutil.copy2(s, d, strict_time_copy=False)
thoughts?
|
Alternatively, we could select which stat to actually copy. We are currently calling def copystat(src, dst, *, ..., preserve=("mode", "ownership", "timestamps", "links", "xattr")):
...
def copy2(src, dst, *, ..., preserve=("mode", "ownership", "timestamps", "links", "xattr")):
...
copystat(src, dst, preserve=preserve)and in the docs we would suggest using copy_function = partial(copy2, preserve=("mode", "ownership", "links", "xattr"))We could also have EDIT: By default we also copy |
|
So, after playing a bit with the implementation:
What we want is for and |
|
Alternative implementation (without tests yet): #142098 |
Uh oh!
There was an error while loading. Please reload this page.