From dcf553c8fd2f055cc256384fc62ef6e059b4c671 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Sat, 10 Apr 2021 17:13:00 +0900 Subject: [PATCH] shared: update chmod util to ignore non-perm bits --- shared/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 9289dab..4e5526b 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -380,11 +380,12 @@ pub fn ensure_dirs_exist(dirs: &[&Path]) -> Result<(), Error> { /// Updates the permissions of a file or directory. Returns `Ok(true)` if /// permissions had to be changed, `Ok(false)` if permissions were already /// correct. -pub fn chmod(file: &File, mode: u32) -> Result { +pub fn chmod(file: &File, new_mode: u32) -> Result { let metadata = file.metadata()?; let mut permissions = metadata.permissions(); - let updated = if permissions.mode() != mode { - permissions.set_mode(mode); + let mode = permissions.mode() & 0o777; + let updated = if mode != new_mode { + permissions.set_mode(new_mode); file.set_permissions(permissions)?; true } else {