Skip to content

Commit

Permalink
Test let_readers_execute on all targets
Browse files Browse the repository at this point in the history
The `let_readers_execute` function computes a new mode with `+x`
set reasonably based on an old mode. It is only useful on Unix-like
systems. But there may be a benefit to being able to detect more
bugs affecting one platform even on another; this can help catch
bugs slightly earlier in the development process.

Now that `let_readers_execute` only longer depends on a type that
varies across Unix-like systems and is only defined on such systems
(instead representing modes as `u32` on all of them), it no longer
contains anything that can't build or be tested everywhere. So this
lets its tests run on all systems, even non-Unix-like ones.
  • Loading branch information
EliahKagan committed Jan 26, 2025
1 parent 51724d1 commit 53ded78
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gix-worktree-state/src/checkout/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ fn set_executable(file: &std::fs::File) -> Result<(), std::io::Error> {
/// Set-user-ID and set-group-ID bits are unset for safety. The sticky bit is also unset.
///
/// This returns only mode bits, not file type. The return value can be used in chmod or fchmod.
#[cfg(unix)]
#[cfg(any(unix, test))]
fn let_readers_execute(mut mode: u32) -> u32 {
assert_eq!(mode & 0o170000, 0o100000, "bug in caller if not from a regular file");
mode &= 0o777; // Clear type, non-rwx mode bits (setuid, setgid, sticky).
mode |= (mode & 0o444) >> 2; // Let readers also execute.
mode
}

#[cfg(all(test, unix))]
#[cfg(test)]
mod tests {
#[test]
fn let_readers_execute() {
Expand Down

0 comments on commit 53ded78

Please sign in to comment.