Skip to content

Commit

Permalink
refactor(module): Improve readalability in Copy
Browse files Browse the repository at this point in the history
Rename masked_mode in `change_permissions` and create copy just if
needed.

Signed-off-by: Alexander Gil <[email protected]>
  • Loading branch information
pando85 committed Jul 4, 2024
1 parent 64e6efa commit 27592bb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rash_core/src/modules/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ fn change_permissions(
mode: u32,
check_mode: bool,
) -> Result<bool> {
let mut dest_permissions_copy = dest_permissions;
let masked_mode = mode & 0o7777;

// & 0o7777 to remove lead 100: 100644 -> 644
if dest_permissions_copy.mode() & 0o7777 != mode & 0o7777 {
if dest_permissions.mode() & 0o7777 != masked_mode {
if !check_mode {
trace!("changing mode: {:o}", &mode);
trace!("changing mode: {:o}", mode);
let mut dest_permissions_copy = dest_permissions;
dest_permissions_copy.set_mode(mode);
set_permissions(dest, dest_permissions_copy)?;
}
return Ok(true);
};
}
Ok(false)
}

Expand Down Expand Up @@ -153,7 +154,6 @@ pub fn copy_file(params: Params, check_mode: bool) -> Result<ModuleResult> {
.create(true)
.open(&params.dest)
} else {
// TODO: avoid this logic.
tempfile()
}
})?;
Expand Down

0 comments on commit 27592bb

Please sign in to comment.