diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-05-03 03:30:59 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-05-03 03:30:59 -0400 |
commit | 6ebf7d55e4c553870306a70092cfb677c17429b9 (patch) | |
tree | 2d20288e44fa627159d0a4e578f0fb506d16f921 /src/dirs.rs | |
parent | 36b5107239b75136ce74799d87a645e153d95948 (diff) | |
download | rbw-6ebf7d55e4c553870306a70092cfb677c17429b9.tar.gz rbw-6ebf7d55e4c553870306a70092cfb677c17429b9.zip |
simplify
Diffstat (limited to 'src/dirs.rs')
-rw-r--r-- | src/dirs.rs | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/src/dirs.rs b/src/dirs.rs index fe610a7..5dd2c35 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -1,23 +1,58 @@ -#[must_use] -pub fn config_dir() -> std::path::PathBuf { +use crate::prelude::*; + +pub fn make_all() -> Result<()> { + std::fs::create_dir_all(&cache_dir()) + .context(crate::error::CreateDirectory)?; + + std::fs::create_dir_all(&runtime_dir()) + .context(crate::error::CreateDirectory)?; + + std::fs::create_dir_all(&data_dir()) + .context(crate::error::CreateDirectory)?; + + Ok(()) +} + +pub fn config_file() -> std::path::PathBuf { + config_dir().join("config.json") +} + +pub fn db_file(email: &str) -> std::path::PathBuf { + cache_dir().join(format!("{}.json", email)) +} + +pub fn pid_file() -> std::path::PathBuf { + runtime_dir().join("pidfile") +} + +pub fn agent_stdout_file() -> std::path::PathBuf { + data_dir().join("agent.out") +} + +pub fn agent_stderr_file() -> std::path::PathBuf { + data_dir().join("agent.err") +} + +pub fn socket_file() -> std::path::PathBuf { + runtime_dir().join("socket") +} + +fn config_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); project_dirs.config_dir().to_path_buf() } -#[must_use] -pub fn cache_dir() -> std::path::PathBuf { +fn cache_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); project_dirs.cache_dir().to_path_buf() } -#[must_use] -pub fn data_dir() -> std::path::PathBuf { +fn data_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); project_dirs.data_dir().to_path_buf() } -#[must_use] -pub fn runtime_dir() -> std::path::PathBuf { +fn runtime_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); project_dirs.runtime_dir().unwrap().to_path_buf() } |