hotfix(logging): fix atomic_create_file and make set_permissions() return an error

This commit is contained in:
Kunal Mohan 2021-05-07 15:40:04 +05:30
parent 23450a708c
commit 2446aec82c
5 changed files with 15 additions and 11 deletions

View file

@ -25,10 +25,10 @@ use zellij_tile::data::Palette;
const UNIX_PERMISSIONS: u32 = 0o700;
pub fn set_permissions(path: &Path) {
let mut permissions = fs::metadata(path).unwrap().permissions();
pub fn set_permissions(path: &Path) -> io::Result<()> {
let mut permissions = fs::metadata(path)?.permissions();
permissions.set_mode(UNIX_PERMISSIONS);
fs::set_permissions(path, permissions).unwrap();
fs::set_permissions(path, permissions)
}
fn into_raw_mode(pid: RawFd) {

View file

@ -42,7 +42,7 @@ pub mod install {
let path = data_dir.join(path);
let parent_path = path.parent().unwrap();
fs::create_dir_all(parent_path).unwrap();
set_permissions(parent_path);
set_permissions(parent_path).unwrap();
if out_of_date || !path.exists() {
fs::write(path, bytes).expect("Failed to install default assets!");
}

View file

@ -30,7 +30,7 @@ lazy_static! {
);
ipc_dir.push(VERSION);
fs::create_dir_all(&ipc_dir).unwrap();
set_permissions(&ipc_dir);
set_permissions(&ipc_dir).unwrap();
ipc_dir.push(&*SESSION_NAME);
ipc_dir
};

View file

@ -11,9 +11,13 @@ use crate::os_input_output::set_permissions;
use crate::utils::consts::{ZELLIJ_TMP_LOG_DIR, ZELLIJ_TMP_LOG_FILE};
pub fn atomic_create_file(file_name: &Path) {
let _ = fs::OpenOptions::new().create(true).open(file_name);
let _ = fs::OpenOptions::new()
.append(true)
.create(true)
.open(file_name)
.unwrap();
#[cfg(not(test))]
set_permissions(file_name);
set_permissions(file_name).unwrap();
}
pub fn atomic_create_dir(dir_name: &Path) -> io::Result<()> {
@ -27,7 +31,7 @@ pub fn atomic_create_dir(dir_name: &Path) -> io::Result<()> {
Ok(())
};
if result.is_ok() {
set_permissions(dir_name);
set_permissions(dir_name)?;
}
result
}
@ -41,7 +45,6 @@ pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> {
atomic_create_file(&*ZELLIJ_TMP_LOG_FILE);
let mut file = fs::OpenOptions::new()
.append(true)
.create(true)
.open(&*ZELLIJ_TMP_LOG_FILE)?;
file.write_all(message.as_bytes())
}
@ -78,6 +81,7 @@ pub fn debug_to_file(message: u8, pid: RawFd) -> io::Result<()> {
let mut file = fs::OpenOptions::new()
.append(true)
.create(true)
.open(path)?;
.open(&path)?;
set_permissions(&path)?;
file.write_all(&[message])
}

View file

@ -87,7 +87,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>) -> thread::JoinHandle<()> {
move || {
drop(std::fs::remove_file(&*ZELLIJ_IPC_PIPE));
let listener = LocalSocketListener::bind(&**ZELLIJ_IPC_PIPE).unwrap();
set_permissions(&*ZELLIJ_IPC_PIPE);
set_permissions(&*ZELLIJ_IPC_PIPE).unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {