Skip to content

Commit d476c06

Browse files
committed
Really convert the mode more portably
While replacing `into()` with `rustix::fs::Mode::from_bits(...)` helped in expressing (and enforcing) the desired semantics for bits that fit in `mode_t` but whose meaning is unrecognized, it did not actually make the code build on macOS, and probably was not enough to improve portability to any other systems where `mode_t` is not `u32`. This commit adds an explicit checked conversion of the value we get from calling `mode()` on a `Permissions` object, which is aways `u32`, into whatever type `mode_t` is defined as, which is `u32` on most systems but `u16` on macOS and possibly others.
1 parent ddaf8a6 commit d476c06

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

gix-worktree-state/src/checkout/entry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ pub(crate) fn finalize_entry(
289289
if let Some(new_perm) = set_mode_executable(old_perm) {
290290
// TODO: If we keep `fchmod`, maybe change `set_mode_executable` not to use `std::fs::Permissions`.
291291
use std::os::unix::fs::PermissionsExt;
292-
let mode = rustix::fs::Mode::from_bits(new_perm.mode())
292+
let raw_mode = new_perm.mode().try_into().expect("mode fits in `st_mode`");
293+
let mode = rustix::fs::Mode::from_bits(raw_mode)
293294
.expect("`set_mode_executable` shouldn't preserve or add unknown bits");
294295
rustix::fs::fchmod(&file, mode).map_err(std::io::Error::from)?;
295296
}

0 commit comments

Comments
 (0)