diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e362ae6..678880eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- [cache] Add `disable-credential-cache` flag (breaking). + ## [0.3.1] - 2021-10-24 ### Changed diff --git a/core/src/cache.rs b/core/src/cache.rs index 612b7c39..da2ad022 100644 --- a/core/src/cache.rs +++ b/core/src/cache.rs @@ -238,29 +238,38 @@ pub struct RemoveFileError(()); impl Cache { pub fn new>( - system_location: Option

, - audio_location: Option

, + credentials_path: Option

, + volume_path: Option

, + audio_path: Option

, size_limit: Option, ) -> io::Result { - if let Some(location) = &system_location { + let mut size_limiter = None; + + if let Some(location) = &credentials_path { fs::create_dir_all(location)?; } - let mut size_limiter = None; + let credentials_location = credentials_path + .as_ref() + .map(|p| p.as_ref().join("credentials.json")); - if let Some(location) = &audio_location { + if let Some(location) = &volume_path { fs::create_dir_all(location)?; + } + + let volume_location = volume_path.as_ref().map(|p| p.as_ref().join("volume")); + + if let Some(location) = &audio_path { + fs::create_dir_all(location)?; + if let Some(limit) = size_limit { let limiter = FsSizeLimiter::new(location.as_ref(), limit); + size_limiter = Some(Arc::new(limiter)); } } - let audio_location = audio_location.map(|p| p.as_ref().to_owned()); - let volume_location = system_location.as_ref().map(|p| p.as_ref().join("volume")); - let credentials_location = system_location - .as_ref() - .map(|p| p.as_ref().join("credentials.json")); + let audio_location = audio_path.map(|p| p.as_ref().to_owned()); let cache = Cache { credentials_location, diff --git a/src/main.rs b/src/main.rs index a3522e8c..ae3258a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,6 +203,7 @@ fn get_setup(args: &[String]) -> Setup { const DEVICE: &str = "device"; const DEVICE_TYPE: &str = "device-type"; const DISABLE_AUDIO_CACHE: &str = "disable-audio-cache"; + const DISABLE_CREDENTIAL_CACHE: &str = "disable-credential-cache"; const DISABLE_DISCOVERY: &str = "disable-discovery"; const DISABLE_GAPLESS: &str = "disable-gapless"; const DITHER: &str = "dither"; @@ -256,6 +257,7 @@ fn get_setup(args: &[String]) -> Setup { "Limits the size of the cache for audio files.", "SIZE" ).optflag("", DISABLE_AUDIO_CACHE, "Disable caching of the audio data.") + .optflag("", DISABLE_CREDENTIAL_CACHE, "Disable caching of credentials.") .optopt("n", NAME, "Device name.", "NAME") .optopt("", DEVICE_TYPE, "Displayed device type. Defaults to 'Speaker'.", "TYPE") .optopt( @@ -559,24 +561,25 @@ fn get_setup(args: &[String]) -> Setup { }; let cache = { - let audio_dir; - let system_dir; - if matches.opt_present(DISABLE_AUDIO_CACHE) { - audio_dir = None; - system_dir = matches - .opt_str(SYSTEM_CACHE) - .or_else(|| matches.opt_str(CACHE)) - .map(|p| p.into()); + let volume_dir = matches + .opt_str(SYSTEM_CACHE) + .or_else(|| matches.opt_str(CACHE)) + .map(|p| p.into()); + + let cred_dir = if matches.opt_present(DISABLE_CREDENTIAL_CACHE) { + None } else { - let cache_dir = matches.opt_str(CACHE); - audio_dir = cache_dir + volume_dir.clone() + }; + + let audio_dir = if matches.opt_present(DISABLE_AUDIO_CACHE) { + None + } else { + matches + .opt_str(CACHE) .as_ref() - .map(|p| AsRef::::as_ref(p).join("files")); - system_dir = matches - .opt_str(SYSTEM_CACHE) - .or(cache_dir) - .map(|p| p.into()); - } + .map(|p| AsRef::::as_ref(p).join("files")) + }; let limit = if audio_dir.is_some() { matches @@ -593,7 +596,7 @@ fn get_setup(args: &[String]) -> Setup { None }; - match Cache::new(system_dir, audio_dir, limit) { + match Cache::new(cred_dir, volume_dir, audio_dir, limit) { Ok(cache) => Some(cache), Err(e) => { warn!("Cannot create cache: {}", e);