diff --git a/src/config.rs b/src/config.rs index 549f17a..6d84372 100644 --- a/src/config.rs +++ b/src/config.rs @@ -38,7 +38,7 @@ fn proj_dirs () -> ProjectDirs { ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths") } -pub fn config_path() -> PathBuf { +pub fn config_path(file: &str) -> PathBuf { let proj_dirs = proj_dirs(); let cfg_dir = proj_dirs.config_dir(); trace!("{:?}", cfg_dir); @@ -46,17 +46,17 @@ pub fn config_path() -> PathBuf { fs::create_dir(cfg_dir).expect("can't create config folder"); } let mut cfg = cfg_dir.to_path_buf(); - cfg.push("config.toml"); + cfg.push(file); cfg } -pub fn cache_path() -> PathBuf { +pub fn cache_path(file: &str) -> PathBuf { let proj_dirs = proj_dirs(); let cache_dir = proj_dirs.cache_dir(); if !cache_dir.exists() { fs::create_dir(cache_dir).expect("can't create cache folder"); } let mut pb = cache_dir.to_path_buf(); - pb.push("playlists.db"); + pb.push(file); pb } diff --git a/src/main.rs b/src/main.rs index 661753f..bb00dba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,7 +98,7 @@ fn main() { // Things here may cause the process to abort; we must do them before creating curses windows // otherwise the error message will not be seen by a user - let path = config::config_path(); + let path = config::config_path("config.toml"); let cfg: config::Config = { let contents = std::fs::read_to_string(&path).unwrap_or_else(|_| { diff --git a/src/playlists.rs b/src/playlists.rs index 0599f24..2329343 100644 --- a/src/playlists.rs +++ b/src/playlists.rs @@ -12,6 +12,8 @@ use spotify::Spotify; use track::Track; use traits::ListItem; +const CACHE_FILE: &str = "playlists.db"; + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Playlist { pub meta: SimplifiedPlaylist, @@ -54,7 +56,7 @@ impl Playlists { store: Arc::new(RwLock::new(Vec::new())), ev: ev.clone(), spotify: spotify.clone(), - cache_path: config::cache_path(), + cache_path: config::cache_path(CACHE_FILE), } }