diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-12 20:11:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-12 20:11:06 +0200 |
| commit | a24c7f79f1ac40f1e8554aa1615b0a7e020c7ca5 (patch) | |
| tree | cf809552c3f676c5dee56873052a5a584e377623 /src | |
| parent | Merge pull request #497 from a-kenji/fix-default-keybind (diff) | |
| parent | Merge branch 'main' of https://github.com/zellij-org/zellij into set-data-dir (diff) | |
| download | sl0ppij-a24c7f79f1ac40f1e8554aa1615b0a7e020c7ca5.tar.gz sl0ppij-a24c7f79f1ac40f1e8554aa1615b0a7e020c7ca5.tar.xz sl0ppij-a24c7f79f1ac40f1e8554aa1615b0a7e020c7ca5.zip | |
Merge pull request #465 from a-kenji/set-data-dir
Add Complile Time System Directories
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/setup.rs | 27 | ||||
| -rw-r--r-- | src/common/utils/consts.rs | 10 | ||||
| -rw-r--r-- | src/server/mod.rs | 8 |
3 files changed, 36 insertions, 9 deletions
diff --git a/src/common/setup.rs b/src/common/setup.rs index 37bf02da..5913211a 100644 --- a/src/common/setup.rs +++ b/src/common/setup.rs @@ -1,6 +1,8 @@ -use crate::common::utils::consts::{SYSTEM_DEFAULT_CONFIG_DIR, VERSION}; +use crate::common::utils::consts::{ + SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_PROJ_DIR, +}; use crate::os_input_output::set_permissions; -use directories_next::{BaseDirs, ProjectDirs}; +use directories_next::BaseDirs; use std::io::Write; use std::{fs, path::Path, path::PathBuf}; @@ -51,6 +53,8 @@ pub mod install { } #[cfg(not(test))] +/// Goes through a predefined list and checks for an already +/// existing config directory, returns the first match pub fn find_default_config_dir() -> Option<PathBuf> { vec![ home_config_dir(), @@ -68,9 +72,24 @@ pub fn find_default_config_dir() -> Option<PathBuf> { None } +/// Looks for an existing dir, uses that, else returns a +/// dir matching the config spec. +pub fn get_default_data_dir() -> PathBuf { + vec![ + xdg_data_dir(), + Path::new(SYSTEM_DEFAULT_DATA_DIR_PREFIX).join("share/zellij"), + ] + .into_iter() + .find(|p| p.exists()) + .unwrap_or_else(xdg_data_dir) +} + pub fn xdg_config_dir() -> PathBuf { - let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); - project_dirs.config_dir().to_owned() + ZELLIJ_PROJ_DIR.config_dir().to_owned() +} + +pub fn xdg_data_dir() -> PathBuf { + ZELLIJ_PROJ_DIR.data_dir().to_owned() } pub fn home_config_dir() -> Option<PathBuf> { diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs index bc8768ce..c77f1c9e 100644 --- a/src/common/utils/consts.rs +++ b/src/common/utils/consts.rs @@ -11,8 +11,16 @@ 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"; +pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir(); + +const fn system_default_data_dir() -> &'static str { + if let Some(data_dir) = std::option_env!("PREFIX") { + data_dir + } else { + &"/usr" + } +} lazy_static! { static ref UID: Uid = Uid::current(); diff --git a/src/server/mod.rs b/src/server/mod.rs index 622a3257..a4a79ca0 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -17,7 +17,7 @@ use crate::common::{ os_input_output::{set_permissions, ServerOsApi}, pty::{pty_thread_main, Pty, PtyInstruction}, screen::{screen_thread_main, ScreenInstruction}, - setup::install::populate_data_dir, + setup::{get_default_data_dir, install::populate_data_dir}, thread_bus::{ChannelWithContext, SenderType, SenderWithContext}, utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_PROJ_DIR}, wasm_vm::{wasm_thread_main, PluginInstruction}, @@ -185,9 +185,9 @@ fn init_session( let to_pty = SenderWithContext::new(SenderType::Sender(to_pty)); // Determine and initialize the data directory - let data_dir = opts - .data_dir - .unwrap_or_else(|| ZELLIJ_PROJ_DIR.data_dir().to_path_buf()); + let data_dir = opts.data_dir.unwrap_or_else(get_default_data_dir); + + #[cfg(enable_automatic_assets_installation)] populate_data_dir(&data_dir); // Don't use default layouts in tests, but do everywhere else |
