Merge pull request #9477 from Ecordonnier/eco/fix-install-as-root

install: do not call chown when called as root
This commit is contained in:
Sylvestre Ledru 2025-12-05 21:08:41 +01:00 committed by GitHub
commit 443c2014fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -711,10 +711,9 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
Ok(())
}
/// Handle incomplete user/group parings for chown.
/// Handle ownership changes when -o/--owner or -g/--group flags are used.
///
/// Returns a Result type with the Err variant containing the error message.
/// If the user is root, revert the uid & gid
///
/// # Parameters
///
@ -735,11 +734,8 @@ fn chown_optional_user_group(path: &Path, b: &Behavior) -> UResult<()> {
// Determine the owner and group IDs to be used for chown.
let (owner_id, group_id) = if b.owner_id.is_some() || b.group_id.is_some() {
(b.owner_id, b.group_id)
} else if geteuid() == 0 {
// Special case for root user.
(Some(0), Some(0))
} else {
// No chown operation needed.
// No chown operation needed - file ownership comes from process naturally.
return Ok(());
};