mv: create cross-device directory entries relative to the destination descriptor - #14971
Open
abendrothj wants to merge 2 commits into
Open
abendrothj wants to merge 2 commits into
abendrothj wants to merge 2 commits into
Conversation
abendrothj
force-pushed
the
mv-cross-device-dir-dirfd
branch
from
September 29, 2026 23:54
d0cf9fe to
f3fc847
Compare
abendrothj
force-pushed
the
mv-cross-device-dir-dirfd
branch
from
September 29, 2026 23:55
f3fc847 to
e3fda2a
Compare
Merging this PR will degrade performance by 27.61%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
GNU testsuite comparison: |
abendrothj
force-pushed
the
mv-cross-device-dir-dirfd
branch
from
September 30, 2026 02:35
e3fda2a to
8d392d1
Compare
Contributor
Author
|
Opened #14991. |
A directory copy needs to create more than files and directories, and each of those has to land relative to a directory descriptor rather than a resolved path. `mkfifoat(2)` does not exist everywhere, so the fifo variant answers Unsupported there and the caller decides; the cfg lists here must stay in step with the ones in nix.
… descriptor The cross-device directory fallback built each destination entry by joining a path, so a symlink dropped into the destination while the copy was running redirected the file content, and its truncation, anywhere the caller could write. Hold the destination directory open and create every entry relative to it. An entry that appears at a name is unlinked and recreated, which is what GNU does, rather than being written through. Ownership, permissions and xattrs then go through the same descriptor, and setuid/setgid are dropped when the chown did not take, as the single-file fallback already does. Targets without safe traversal keep the path-based behavior, creating entries in a way that still refuses to follow a symlink.
abendrothj
force-pushed
the
mv-cross-device-dir-dirfd
branch
from
October 1, 2026 01:14
8d392d1 to
5e3cb57
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a directory move falls back to copying across filesystems, each destination entry was created by joining a path, and regular files went through
fs::copy. A symlink that appeared in the destination while the copy was running was followed, so the content went to wherever it pointed.The destination directory is now held open and every entry (files, subdirectories, symlinks, FIFOs, hard links) is created relative to it without following symlinks. An entry that appears at a name is unlinked and recreated. Ownership and mode of copied files are set through the open descriptor, dropping setuid/setgid when the chown fails, as the single-file fallback already does. The first commit adds the
symlinkat/mkfifoat/linkathelpers toDirFdin uucore.Closes #14991