Merge pull request #872 from JasonLG1979/add-disable-credential-cache-flag

Add disable credential cache flag
This commit is contained in:
Roderick van Domburg 2021-10-28 15:18:34 +02:00 committed by GitHub
commit 5049cd76e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 27 deletions

View file

@ -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

View file

@ -238,29 +238,38 @@ pub struct RemoveFileError(());
impl Cache {
pub fn new<P: AsRef<Path>>(
system_location: Option<P>,
audio_location: Option<P>,
credentials_path: Option<P>,
volume_path: Option<P>,
audio_path: Option<P>,
size_limit: Option<u64>,
) -> io::Result<Self> {
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,

View file

@ -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
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::<Path>::as_ref(p).join("files"));
system_dir = matches
.opt_str(SYSTEM_CACHE)
.or(cache_dir)
.map(|p| p.into());
}
.map(|p| AsRef::<Path>::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);