Skip to content

mv: recreate special files in directories moved across devices - #15123

Draft
abendrothj wants to merge 6 commits into
uutils:mainfrom
abendrothj:mv-special-files-in-moved-dirs
Draft

abendrothj wants to merge 6 commits into
uutils:mainfrom
abendrothj:mv-special-files-in-moved-dirs

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/mv/mv-special-1 is no longer failing!

@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 11.73%

1 warning, 1 note

⚠️ 124 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

❌ 2 regressed benchmarks
✅ 411 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation mv_force_overwrite 128.3 ms 156.8 ms -18.16%
❌ CPU Simulation df_deep_directory 886.7 µs 931.5 µs -4.8%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:mv-special-files-in-moved-dirs (3a4e7de) with main (293a724)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (36079aa) during the generation of this report, so 293a724 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@abendrothj
abendrothj marked this pull request as draft October 7, 2026 00:20
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch 3 times, most recently from 60d24ea to 5b7ce0f Compare October 12, 2026 10:05
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch 3 times, most recently from a9dc76d to 7334d83 Compare October 22, 2026 08:50
@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

Comment thread src/uu/mv/src/mv.rs
}

if from.is_symlink() {
let metadata = from.symlink_metadata()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just created this directory ourselves, do we really need a staging dir + rename for every special file in it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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.

Comment thread src/uu/mv/src/mv.rs
let mode = metadata.mode() as nix::libc::mode_t;
mknod(
to,
SFlag::from_bits_truncate(mode & nix::libc::S_IFMT),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same owned/mode logic as in create_special_file_at, could be dedup, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/uu/mv/src/mv.rs
fn copy_special_file(to: &Path, metadata: &fs::Metadata) -> io::Result<()> {
let parent = to
.parent()
.filter(|p| !p.as_os_str().is_empty())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot of machinery for a fifo, could it be simpler?
and the comments are pretty long, please make them shorter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/uu/mv/src/mv.rs
fs::remove_file(from)
let mode = metadata.mode() as nix::libc::mode_t;
mknod(
to,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chown by path after mknod on these platforms, isn't that racy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch 3 times, most recently from c1f5076 to 7abea17 Compare November 11, 2026 04:54
@sylvestre
sylvestre force-pushed the mv-special-files-in-moved-dirs branch 2 times, most recently from e4796d8 to 765f7d9 Compare November 17, 2026 10:54
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.
@sylvestre
sylvestre force-pushed the mv-special-files-in-moved-dirs branch from 765f7d9 to 3a4e7de Compare November 17, 2026 17:55
@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.52 MB (+140 KB, +0.09%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@sylvestre

Copy link
Copy Markdown
Contributor

@codspeedbot fix this regression

@codspeed

codspeed Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

@codspeedbot fix this regression

I could not reproduce the mv_force_overwrite regression, so there is nothing to fix in this PR.

What I measured. I ran the 4 mv benchmarks in CPU simulation on the same machine, once on the PR's merge base (36079aa) and once on the PR head (3a4e7de). Comparison:

Benchmark main (36079aa) PR (3a4e7de)
mv_force_overwrite 68.07 ms 67.67 ms
mv_single_file 62.61 ms 62.88 ms
mv_multiple_to_dir 11.16 ms 11.17 ms
mv_directory 3.23 ms 3.12 ms

All four are within noise. CodSpeed flags mv_directory as 3.6% faster, but that difference is also within noise.

Why the old report showed a regression:

  • mv_force_overwrite only renames files on the same device. It never reaches the new copy_special_file path, which runs only for cross-device moves of special files.
  • The CI run for the previous push (e4796d8) measured mv_force_overwrite at 128.4 ms, against 128.3 ms on main. The -18% from the older report did not appear again.
  • In that report, the other changes (df_deep_directory, join_*, factor_*) were measured on a different CPU on each side. df and join are not touched by this PR.

About the latest report: CodSpeed failed to process the CI run for 3a4e7de, so the PR comment now shows an error instead of results. This is a problem on CodSpeed's side, not in your code. A new CI run, for example after the next push, should produce a normal report.

If you want me to check the next report when it arrives, comment:

@codspeedbot check the latest CodSpeed report on this PR
Summary
  • Warming up the performance wizard...
  • Check the PR's CodSpeed runs and the mv_force_overwrite regression — Latest run (3a4e7de) failed to process. Previous run (e4796d8) had mv_force_overwrite at 128.4 ms, same as main (128.3 ms).
  • Measure mv benchmarks locally on main vs PR head — Simulation, same machine, base 36079aa vs head 3a4e7de
  • Handling comment — Comment handling finished successfully

Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.

@abendrothj

Copy link
Copy Markdown
Contributor Author

Thanks for rebasing it! It still includes #15122 and #13334, so merging it would land all three. Should I mark it ready, or would you rather go through those first? The staging for files in moved directories goes away once #16338 is in.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mv: moving a directory with a socket or device node across filesystems fails

3 participants