diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 5539ae70..6f891e0d 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -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) { diff --git a/src/common/setup.rs b/src/common/setup.rs index edfa858a..2eceba18 100644 --- a/src/common/setup.rs +++ b/src/common/setup.rs @@ -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!"); } diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs index a46f8243..bc8768ce 100644 --- a/src/common/utils/consts.rs +++ b/src/common/utils/consts.rs @@ -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 }; diff --git a/src/common/utils/logging.rs b/src/common/utils/logging.rs index ff3fb44c..4c53e2b2 100644 --- a/src/common/utils/logging.rs +++ b/src/common/utils/logging.rs @@ -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]) } diff --git a/src/server/mod.rs b/src/server/mod.rs index 6eb2455b..c0cf482c 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -87,7 +87,7 @@ pub fn start_server(os_input: Box) -> 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) => {