From c5a080d2a03b68949642f1446504a981661a0e54 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 23 Oct 2019 05:16:47 -0400 Subject: if the home directory is set to /, treat it as nonexistent this is how system users typically indicate not having a home directory --- src/dirs.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/dirs.rs b/src/dirs.rs index 937cfcb..bd4741d 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -22,14 +22,24 @@ impl Dirs { Ok(()) } + fn has_home(&self) -> bool { + directories::BaseDirs::new().map_or(false, |dirs| { + dirs.home_dir() != std::path::Path::new("/") + }) + } + fn global_config_dir(&self) -> &std::path::Path { std::path::Path::new("/etc/teleterm") } fn config_dir(&self) -> Option<&std::path::Path> { - self.project_dirs - .as_ref() - .map(directories::ProjectDirs::config_dir) + if self.has_home() { + self.project_dirs + .as_ref() + .map(directories::ProjectDirs::config_dir) + } else { + None + } } pub fn config_file( @@ -57,9 +67,13 @@ impl Dirs { } fn data_dir(&self) -> Option<&std::path::Path> { - self.project_dirs - .as_ref() - .map(directories::ProjectDirs::data_dir) + if self.has_home() { + self.project_dirs + .as_ref() + .map(directories::ProjectDirs::data_dir) + } else { + None + } } pub fn data_file( -- cgit v1.2.3-54-g00ecf