Skip to content

Commit

Permalink
Merge pull request #616 from lopopolo/lopopolo/nix-for-history-umask
Browse files Browse the repository at this point in the history
Use `nix` APIs for `umask` munging in `history` module
  • Loading branch information
gwenn authored Apr 11, 2022
2 parents 01d01d8 + f905c6d commit 8b0877a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,21 @@ cfg_if::cfg_if! {

fn fix_perm(_: &File) {}
} else if #[cfg(unix)] {
fn umask() -> libc::mode_t {
unsafe { libc::umask(libc::S_IXUSR | libc::S_IRWXG | libc::S_IRWXO) }
fn umask() -> nix::sys::stat::Mode {
use nix::sys::stat::Mode;

nix::sys::stat::umask(Mode::S_IXUSR | Mode::S_IRWXG | Mode::S_IRWXO)
}

fn restore_umask(old_umask: libc::mode_t) {
unsafe {
libc::umask(old_umask);
}
fn restore_umask(old_umask: nix::sys::stat::Mode) {
nix::sys::stat::umask(old_umask);
}

fn fix_perm(file: &File) {
use std::os::unix::io::AsRawFd;
unsafe {
libc::fchmod(file.as_raw_fd(), libc::S_IRUSR | libc::S_IWUSR);
}
use nix::sys::stat::{fchmod, Mode};

let _ = fchmod(file.as_raw_fd(), Mode::S_IRUSR | Mode::S_IWUSR);
}
}
}
Expand Down

0 comments on commit 8b0877a

Please sign in to comment.