Preserve directory modes when cloning paths across branches

- Restore source permissions after ownership to preserve setgid and clear unwanted inherited mode bits.
- Add regression coverage for directory modes, group inheritance, and existing destination directories.
- Update the branch configuration test to use the current API.
- Document metadata preservation when cloning directory paths.
This commit is contained in:
Antonio SJ Musumeci 2026-11-04 18:27:07 -06:00 • committed by trapexit
parent 5d5d7af90b
commit 74eade91f5
3 changed files with 57 additions and 0 deletions

View file

@ -21,6 +21,7 @@
#include "errno.h"
#include "fs_attr.hpp"
#include "fs_clonepath.hpp"
#include "fs_lchmod.hpp"
#include "fs_lchown.hpp"
#include "fs_lstat.hpp"
#include "fs_lutimens.hpp"
@ -111,6 +112,13 @@ fs::clonepath(const fs::path &srcpath_,
if(return_metadata_errors_ && (rv < 0))
return rv;
// mkdir(2) on Linux ignores S_ISUID/S_ISGID in mode and may
// inherent S_ISGID from the parent. Explicitly set the mode after
// chown so the clone matches the source.
rv = fs::lchmod_check_on_error(dstpath,st.st_mode);
if(return_metadata_errors_ && (rv < 0))
return rv;
rv = fs::lutimens(dstpath,st);
if(return_metadata_errors_ && (rv < 0))
return rv;