Skip to content

mv: set a cross-device directory's owner after copying its contents - #16338

Open
abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:mv-cross-device-chown-after-contents
Open

abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:mv-cross-device-chown-after-contents

Conversation

@abendrothj

Copy link
Copy Markdown
Contributor

When mv copies a directory across filesystems (the EXDEV fallback), each
destination directory was chowned to the source owner before its contents were
copied into it. Set the owner, like the mode, only after the contents are in
place, through the directory's descriptor, matching GNU.

Two notes on the change:

  • The directory chown is now fchown on its O_NOFOLLOW descriptor (libc, so
    fakeroot still intercepts it) rather than lchown by path — same effect on a
    directory.
  • If the move fails partway, the partial destination directory is left owned by
    the user running mv (mode 0700), not the source owner. mv leaves a partial
    either way.

Files, symlinks and special files inside the directory, and single-file moves,
are unchanged; a successful move's result (owner, mode, xattrs) is the same as
before. A root-only ordering check is added to util/check-safe-traversal.sh.

The cross-device fallback chowned each created directory to the source
owner before copying its contents into it. Set the owner, like the mode,
only once the contents are in place, through the directory's descriptor.
Copilot AI balanced review requested due to automatic review settings November 11, 2026 03:21

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 insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

2 participants