Unify how file mode is specified

The lines of code I commented on in #10254 were meant to serve only as examples
of the changes I was requesting, not the only instances.

Also just use `Mode::from_bits_truncate()` instead of unsafe or unwrapping since
we know the modes are correct.
This commit is contained in:
Mahmoud Al-Qudsi 2024-01-28 18:09:52 -06:00
parent 6877773fdd
commit 99bd2e71d0
4 changed files with 4 additions and 8 deletions

View File

@ -341,7 +341,7 @@ fn test_autoload() {
let fd = wopen_cloexec(
path,
OFlag::O_RDWR | OFlag::O_CREAT,
Mode::from_bits(0o666).unwrap(),
Mode::from_bits_truncate(0o666),
)
.unwrap();
write_loop(&fd, "Hello".as_bytes()).unwrap();

View File

@ -441,11 +441,7 @@ impl EnvUniversal {
let mut res_fd = None;
while res_fd.is_none() {
let fd = match wopen_cloexec(
&self.vars_path,
flags,
Mode::S_IRUSR | Mode::S_IWUSR | Mode::S_IRGRP | Mode::S_IROTH,
) {
let fd = match wopen_cloexec(&self.vars_path, flags, Mode::from_bits_truncate(0o644)) {
Ok(fd) => fd,
Err(err) => {
if err == nix::Error::EINTR {

View File

@ -128,7 +128,7 @@ const HISTORY_SAVE_MAX: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1024
const HISTORY_OUTPUT_BUFFER_SIZE: usize = 64 * 1024;
/// The file access mode we use for creating history files
const HISTORY_FILE_MODE: Mode = Mode::S_IRUSR.union(Mode::S_IWUSR);
const HISTORY_FILE_MODE: Mode = Mode::from_bits_truncate(0o600);
/// How many times we retry to save
/// Saving may fail if the file is modified in between our opening

View File

@ -1007,7 +1007,7 @@ const FILE_ERROR: &wstr = L!("An error occurred while redirecting file '%ls'");
const NOCLOB_ERROR: &wstr = L!("The file '%ls' already exists");
/// Base open mode to pass to calls to open.
const OPEN_MASK: Mode = unsafe { Mode::from_bits_unchecked(0o666) };
const OPEN_MASK: Mode = Mode::from_bits_truncate(0o666);
/// Provide the fd monitor used for background fillthread operations.
fn fd_monitor() -> &'static mut FdMonitor {