diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-05 02:00:02 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-06 22:01:27 +0530 |
| commit | 7982636741df86e7323f73726631ef15745b15fc (patch) | |
| tree | 7578a69fbe76af202c18f59f387da64504673226 /src/common/utils | |
| parent | Fix after rebase (diff) | |
| download | sl0ppij-7982636741df86e7323f73726631ef15745b15fc.tar.gz sl0ppij-7982636741df86e7323f73726631ef15745b15fc.tar.xz sl0ppij-7982636741df86e7323f73726631ef15745b15fc.zip | |
explicitly set file and directory permissions
Diffstat (limited to 'src/common/utils')
| -rw-r--r-- | src/common/utils/consts.rs | 6 | ||||
| -rw-r--r-- | src/common/utils/logging.rs | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs index 4c219fed..a46f8243 100644 --- a/src/common/utils/consts.rs +++ b/src/common/utils/consts.rs @@ -1,5 +1,6 @@ //! Zellij program-wide constants. +use crate::os_input_output::set_permissions; use directories_next::ProjectDirs; use lazy_static::lazy_static; use nix::unistd::Uid; @@ -8,6 +9,7 @@ use std::{env, fs}; pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE"; pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR"; +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); // TODO: ${PREFIX} argument in makefile pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij"; @@ -18,7 +20,6 @@ lazy_static! { pub static ref ZELLIJ_PROJ_DIR: ProjectDirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); pub static ref ZELLIJ_IPC_PIPE: PathBuf = { - let version = env::var("CARGO_PKG_VERSION").unwrap(); let mut ipc_dir = env::var("ZELLIJ_SOCKET_DIR").map_or_else( |_| { ZELLIJ_PROJ_DIR @@ -27,8 +28,9 @@ lazy_static! { }, PathBuf::from, ); - ipc_dir.push(&version); + ipc_dir.push(VERSION); fs::create_dir_all(&ipc_dir).unwrap(); + set_permissions(&ipc_dir); ipc_dir.push(&*SESSION_NAME); ipc_dir }; diff --git a/src/common/utils/logging.rs b/src/common/utils/logging.rs index d99a2428..ff3fb44c 100644 --- a/src/common/utils/logging.rs +++ b/src/common/utils/logging.rs @@ -7,14 +7,17 @@ use std::{ path::{Path, PathBuf}, }; +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); + #[cfg(not(test))] + set_permissions(file_name); } pub fn atomic_create_dir(dir_name: &Path) -> io::Result<()> { - if let Err(e) = fs::create_dir(dir_name) { + let result = if let Err(e) = fs::create_dir(dir_name) { if e.kind() == std::io::ErrorKind::AlreadyExists { Ok(()) } else { @@ -22,7 +25,11 @@ pub fn atomic_create_dir(dir_name: &Path) -> io::Result<()> { } } else { Ok(()) + }; + if result.is_ok() { + set_permissions(dir_name); } + result } pub fn debug_log_to_file(mut message: String) -> io::Result<()> { |
