Skip to content

Commit

Permalink
Really convert the mode more portably
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EliahKagan committed Jan 21, 2025
1 parent ba92611 commit 3afb4f1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gix-worktree-state/src/checkout/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ pub(crate) fn finalize_entry(
if let Some(new_perm) = set_mode_executable(old_perm) {
// TODO: If we keep `fchmod`, maybe change `set_mode_executable` not to use `std::fs::Permissions`.
use std::os::unix::fs::PermissionsExt;
let mode = rustix::fs::Mode::from_bits(new_perm.mode())
let raw_mode = new_perm.mode().try_into().expect("mode fits in `st_mode`");
let mode = rustix::fs::Mode::from_bits(raw_mode)
.expect("`set_mode_executable` shouldn't preserve or add unknown bits");
rustix::fs::fchmod(&file, mode).map_err(std::io::Error::from)?;
}
Expand Down

0 comments on commit 3afb4f1

Please sign in to comment.