mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 03:51:14 -03:00
Set file permissions via stdlib method
This commit is contained in:
committed by
Johannes Altmanninger
parent
21e284e548
commit
70d682a110
@@ -779,13 +779,12 @@ fn save(&mut self, directory: &wstr) -> bool {
|
||||
|
||||
// Ensure we maintain ownership and permissions (#2176).
|
||||
if let Ok(md) = wstat(&real_path) {
|
||||
// TODO: Consider replacing with std::os::unix::fs::fchown when MSRV >= 1.73
|
||||
if unsafe { libc::fchown(private_file.as_raw_fd(), md.uid(), md.gid()) } == -1 {
|
||||
FLOG!(uvar_file, "universal log fchown() failed");
|
||||
FLOG!(uvar_file, "universal log fchown() failed:", errno());
|
||||
}
|
||||
#[allow(clippy::useless_conversion)]
|
||||
let mode: libc::mode_t = md.mode().try_into().unwrap();
|
||||
if unsafe { libc::fchmod(private_file.as_raw_fd(), mode) } == -1 {
|
||||
FLOG!(uvar_file, "universal log fchmod() failed");
|
||||
if let Err(e) = private_file.set_permissions(md.permissions()) {
|
||||
FLOG!(uvar_file, "universal log setting permissions failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use libc::{fchmod, fchown, flock, LOCK_EX, LOCK_SH, LOCK_UN};
|
||||
use libc::{fchown, flock, LOCK_EX, LOCK_SH, LOCK_UN};
|
||||
use lru::LruCache;
|
||||
use nix::{fcntl::OFlag, sys::stat::Mode};
|
||||
use rand::Rng;
|
||||
@@ -767,6 +767,7 @@ fn save_internal_via_rewrite(&mut self) {
|
||||
// case right either).
|
||||
if let Ok(target_file_after) = target_file_after.as_ref() {
|
||||
if let Ok(md) = target_file_after.metadata() {
|
||||
// TODO: Consider replacing with std::os::unix::fs::fchown when MSRV >= 1.73
|
||||
if unsafe { fchown(tmp_file.as_raw_fd(), md.uid(), md.gid()) } == -1 {
|
||||
FLOG!(
|
||||
history_file,
|
||||
@@ -774,15 +775,8 @@ fn save_internal_via_rewrite(&mut self) {
|
||||
errno::errno()
|
||||
);
|
||||
}
|
||||
#[allow(clippy::useless_conversion)]
|
||||
if unsafe { fchmod(tmp_file.as_raw_fd(), md.mode().try_into().unwrap()) }
|
||||
== -1
|
||||
{
|
||||
FLOG!(
|
||||
history_file,
|
||||
"Error when changing mode of history file:",
|
||||
errno::errno(),
|
||||
);
|
||||
if let Err(e) = tmp_file.set_permissions(md.permissions()) {
|
||||
FLOG!(history_file, "Error when changing mode of history file:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user