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

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. Run on macOS and Linux. On Debian GNU/Hurd the mv tests fail only where main does (the new ones are Linux-only), and a cross-device move of a 0640 FIFO, alone or in a directory, keeps its mode as with GNU 9.10. AIX is only cross-checked with clippy.

Based on #13334.

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

Merging this PR will degrade performance by 9.99%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
❌ 25 regressed benchmarks
✅ 370 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory dd_copy_default 19.7 KB 28.6 KB -31.08%
❌ Memory dd_copy_with_skip 23.1 KB 32.3 KB -28.48%
❌ Memory dd_copy_with_seek 23.1 KB 32.3 KB -28.48%
❌ Memory dd_copy_4k_blocks 23.1 KB 31.9 KB -27.83%
❌ Memory dd_copy_partial 23.1 KB 32 KB -27.82%
❌ Memory dd_copy_8k_blocks 27.1 KB 35.9 KB -24.73%
❌ Simulation split_lines 8.5 ms 11.1 ms -23.5%
❌ Simulation split_numeric_suffix 8.7 ms 11.4 ms -23.08%
❌ Simulation true_consecutive_calls 294.7 ns 350.2 ns -15.86%
❌ Simulation five_38_bit_primes 1.5 s 1.8 s -15.09%
❌ Simulation check_sorted_utf8_locale 422.9 ms 492.3 ms -14.09%
❌ Simulation sort_numeric_utf8_locale 36.1 ms 40.7 ms -11.4%
❌ Simulation merge_single_file_utf8_locale 119.3 ms 133.2 ms -10.46%
❌ Simulation tsort_complex_dag[50000] 87.6 ms 97.2 ms -9.79%
❌ Memory dd_copy_64k_blocks 83.1 KB 91.9 KB -9.67%
❌ Simulation tsort_tree_dag[(10, 3)] 36.5 ms 39.4 ms -7.32%
❌ Simulation tsort_wide_dag[100000] 157.6 ms 167 ms -5.65%
❌ Simulation merge_pre_sorted_files_utf8_locale 237.9 ms 252 ms -5.6%
❌ Simulation merge_pre_sorted_files 238.7 ms 252.5 ms -5.49%
❌ Memory dd_copy_separate_blocks 185.4 KB 194.8 KB -4.83%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

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 (60d24ea) with main (fe26d56)

Open in CodSpeed

Footnotes

  1. 54 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. ↩

@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 from 66235c5 to 1091c4d Compare October 7, 2026 00:54
Open a directory readable, and on EACCES retry with O_PATH or O_SEARCH,
which anchor *at calls without read access. The targets with either flag
are named by the has_o_path and has_o_search cfg aliases. If the retry
fails, its own error is returned.
Move the temporary name and renameat logic of replace_link into
replace_entry_at, which creates the entry through a callback relative to
an open directory, so other callers can replace entries the same way.

The parent is now opened with DirFd::open_anchor, so ln -sf replacing a
link in a directory with write and search but no read permission works,
as it does with GNU, instead of failing with EACCES.
Create fifos, sockets and device nodes relative to an open directory.
nix and rustix do not provide mknodat on Apple targets, so this calls
libc directly.
A cross-device move of a socket or device node went through the
regular file copy, which removed the destination and then failed to
open the source. A fifo also removed the destination before creating
the new one, and lost its mode.

Fifos, sockets and device nodes are now created with their mode and
ownership in a private directory next to the destination and renamed
over it, so the destination is kept if the node cannot be created, and
the ownership and mode cannot land on another file linked over the
destination name meanwhile. The private directory is made 0700 by name
right after it is created, before it is opened, without changing the
umask; the check after the open rejects a directory moved there in
between. As for regular files, setuid and setgid are dropped when the
ownership cannot be kept.

Fixes uutils#13145
Sockets and device nodes inside a directory moved across devices went
through the regular file copy, which cannot open them, so the move
failed. Fifos were recreated with mode 0666 minus the umask. Recreate
all of them with copy_special_file, which keeps the mode.
@abendrothj
abendrothj force-pushed the mv-special-files-in-moved-dirs branch from 1091c4d to 60d24ea Compare October 7, 2026 08:21

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

2 participants