-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Preserve times for fs::copy on Unix. #32067
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This adds `set_times` to `File` so `fs::copy` can restore the access, modified and created times. Also permissions are now set during file creation, as a partly fix for #26933.
if !from.is_file() { | ||
use fs::OpenOptions; | ||
let mut from_opts = OpenOptions::new(); | ||
let mut reader = try!(from_opts.read(true).open(&from)); |
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.
Shouldn't this be the same as File::open
?
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.
Now I don't remember why I changed that...
If I don't find the reason I will change it back.
I'm curious if other versions of this function in other libraries also copy times by default? I wonder if this should perhaps be an opt-in behavior? |
I would have to look, but I think it is nice to imitate cp as close as possible on Unix |
Ah ok, if |
This is probably for avoiding possible performance hit caused by inode access. |
☔ The latest upstream changes (presumably #32390) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
This adds
set_times
toFile
sofs::copy
can restore the access, modified and created times.Also permissions are now set during file creation, as a partly fix for #26933.
I did not test the code for setting the creation time, as I do not have BSD.
It probably works as long as the creation time is earlier than what it is currently set to.
If we want to make a method like this public, we probably should add a way to keep some times the same, or set them to the current time.
There are still some things left for #26933, like copying attributes, extended attributes and ACLs.