Skip to content

Commit

Permalink
fixup! uucore(perms): better support nameless uids, gids
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinkels committed May 10, 2022
1 parent bfb7479 commit 338233c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ pub fn wrap_chown<P: AsRef<Path>>(
"{}\nfailed to change group of {} from {} to {}",
out,
path.quote(),
entries::gid2grp(gid).unwrap_or(gid.to_string()),
entries::gid2grp(dest_gid).unwrap_or(dest_gid.to_string())
entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()),
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
} else {
let uid = meta.uid();
Expand All @@ -107,10 +107,10 @@ pub fn wrap_chown<P: AsRef<Path>>(
"{}\nfailed to change ownership of {} from {}:{} to {}:{}",
out,
path.quote(),
entries::uid2usr(uid).unwrap_or(uid.to_string()),
entries::gid2grp(gid).unwrap_or(gid.to_string()),
entries::uid2usr(dest_uid).unwrap_or(dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or(dest_gid.to_string())
entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()),
entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()),
entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
};
};
Expand All @@ -127,19 +127,19 @@ pub fn wrap_chown<P: AsRef<Path>>(
format!(
"changed group of {} from {} to {}",
path.quote(),
entries::gid2grp(gid).unwrap_or(gid.to_string()),
entries::gid2grp(dest_gid).unwrap_or(dest_gid.to_string())
entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()),
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
} else {
let gid = meta.gid();
let uid = meta.uid();
format!(
"changed ownership of {} from {}:{} to {}:{}",
path.quote(),
entries::uid2usr(uid).unwrap_or(uid.to_string()),
entries::gid2grp(gid).unwrap_or(gid.to_string()),
entries::uid2usr(dest_uid).unwrap_or(dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or(dest_gid.to_string())
entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()),
entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()),
entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
};
}
Expand All @@ -156,8 +156,8 @@ pub fn wrap_chown<P: AsRef<Path>>(
format!(
"ownership of {} retained as {}:{}",
path.quote(),
entries::uid2usr(dest_uid).unwrap_or(dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or(dest_gid.to_string())
entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()),
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
};
}
Expand Down

0 comments on commit 338233c

Please sign in to comment.