Repository navigation
mv: keep mode and xattrs of subdirectories on a cross-device move - #16222
Conversation
The cross-device fallback created each directory below the operand with the default mode and never copied its xattrs, so POSIX ACLs were lost and a 0700 directory became 0755. Copy the xattrs and then set the mode once the directory's contents are in place. The mode goes last because chmod sets the ACL mask from the group bits. Closes uutils#15784
There was a problem hiding this comment.
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.
| )?; | ||
|
|
||
| #[cfg(unix)] | ||
| copy_subdir_xattrs_and_mode(&from_path, &to_path, ownership_preserved); |
There was a problem hiding this comment.
the top-level dir has the same problem: mv of a 0700 dir across devices still gives 0755.
could you please apply the mode in rename_dir_fallback too?
| } else { | ||
| mode & !0o6000 | ||
| }; | ||
| let _ = fs::set_permissions(to, fs::Permissions::from_mode(mode)); |
There was a problem hiding this comment.
rename_file_fallback does this through fds (copy_xattrs_fd_ignore_unsupported + set_permissions on the File), could you do the same here?
the path-based chmod follows a symlink swapped in at to.
There was a problem hiding this comment.
Added new helper open_dir_nofollow
| let mode = if ownership_preserved { | ||
| mode | ||
| } else { | ||
| mode & !0o6000 |
There was a problem hiding this comment.
same setuid/setgid strip as in rename_file_fallback, could be a small shared helper, no?
There was a problem hiding this comment.
Added new helper moved_mode
| .permissions() | ||
| .mode() | ||
| & 0o7777; | ||
| assert_eq!(mode, 0o700, "site/private should stay 0700, got {mode:o}"); |
There was a problem hiding this comment.
please also chmod site to 0700 and check it after the move
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Thanks for your PR |
When
mvfalls back to copying a directory tree across filesystems, the directories below the operand were created with the default mode and never got their xattrs, so POSIX ACLs were lost and a 0700 subdirectory came out as 0755.After a subdirectory's contents are copied, its xattrs are now copied and then its mode is set, with setuid/setgid dropped if the chown did not take, as for files. Doing it after the contents means a default ACL or a read-only mode does not affect the entries created inside it, and setting the mode last keeps the ACL mask right.
The new test checks the mode, and the ACL when both filesystems support ACLs (
/dev/shmtmpfs often does not, so I also checked it by hand with an ext4 destination).Closes #15784