Repository navigation
mv: recreate special files in directories moved across devices - #15123
abendrothj wants to merge 6 commits into
Conversation
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 11.73%1 warning, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
60d24ea to
5b7ce0f
Compare
a9dc76d to
7334d83
Compare
|
sorry but it needs to be rebased |
| } | ||
|
|
||
| if from.is_symlink() { | ||
| let metadata = from.symlink_metadata()?; |
There was a problem hiding this comment.
we just created this directory ourselves, do we really need a staging dir + rename for every special file in it?
There was a problem hiding this comment.
Good point. GNU creates these directories 0700 and sets their mode after the contents, so nothing in them needs staging. #16222 adds the second half; once it's in, I'll create them 0700 while they're filled and drop the staging for files inside them. It stays for a special file moved into an existing directory.
There was a problem hiding this comment.
#16222 is in, but moved directories still get their owner before their contents, so the files inside them still need the staging. #16338 moves the chown after the contents; once it's merged I'll drop the staging here for files inside moved directories. It stays for a special file moved into an existing directory, so a failed move leaves the destination in place.
| let mode = metadata.mode() as nix::libc::mode_t; | ||
| mknod( | ||
| to, | ||
| SFlag::from_bits_truncate(mode & nix::libc::S_IFMT), |
There was a problem hiding this comment.
same owned/mode logic as in create_special_file_at, could be dedup, no?
There was a problem hiding this comment.
That one is the Redox fallback. It shares special_file_mode with the staged version; only the mknod and the chown and chmod by path stay, since Redox has no safe_traversal.
| fn copy_special_file(to: &Path, metadata: &fs::Metadata) -> io::Result<()> { | ||
| let parent = to | ||
| .parent() | ||
| .filter(|p| !p.as_os_str().is_empty()) |
There was a problem hiding this comment.
this is a lot of machinery for a fifo, could it be simpler?
and the comments are pretty long, please make them shorter
There was a problem hiding this comment.
Comments are down to two lines. The machinery is the staging from the other thread, which goes for moved directories once they're created 0700.
| fs::remove_file(from) | ||
| let mode = metadata.mode() as nix::libc::mode_t; | ||
| mknod( | ||
| to, |
There was a problem hiding this comment.
chown by path after mknod on these platforms, isn't that racy?
There was a problem hiding this comment.
Yes, it is. That fallback is only for Redox now, where safe_traversal isn't built. Everywhere else the node is chowned in the private directory before it's moved in.
c1f5076 to
7abea17
Compare
e4796d8 to
765f7d9
Compare
For ln -f/-sf, cp -lf/-sf and mv's cross-device symlink. Without O_PATH or O_SEARCH (OpenBSD, Hurd) it falls back to the directory's path.
ln and mv's cross-device move use it next. The no-unique-temp-name error is now translated.
On Apple targets mknodat is looked up at run time, as it exists only from macOS 13; before that the node is created by the directory's path.
Sockets and device nodes are recreated like fifos, with their mode, and the destination is replaced only once the new node exists. Fixes uutils#13145
Sockets and device nodes in the directory no longer fail the move, and fifos keep their mode.
765f7d9 to
3a4e7de
Compare
|
Binary size comparison: |
|
@codspeedbot fix this regression |
I could not reproduce the What I measured. I ran the 4 mv benchmarks in CPU simulation on the same machine, once on the PR's merge base (
All four are within noise. CodSpeed flags Why the old report showed a regression:
About the latest report: CodSpeed failed to process the CI run for If you want me to check the next report when it arrives, comment: Summary
Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot. |
Based on #13334; only the last commit is new here.
Sockets and device nodes inside a directory moved across devices went through the regular file copy, which can't open them, so the move failed. FIFOs were recreated with mode 0666 minus the umask. All of them now go through
copy_special_file, which keeps the mode; as non-root, device nodes (and sockets on macOS) still fail, as with GNU. Test:test_mv_cross_device_dir_with_special_files. Run on macOS and Linux.Closes #15113
Related to #13145