mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Add disable credential cache flag
As mentioned in https://github.com/librespot-org/librespot/discussions/870, this allows someone who would otherwise like to take advantage of audio file and volume caching to disable credential caching.
This commit is contained in:
parent
b4784ebf9c
commit
52bd212e43
2 changed files with 32 additions and 14 deletions
|
@ -238,29 +238,38 @@ pub struct RemoveFileError(());
|
|||
|
||||
impl Cache {
|
||||
pub fn new<P: AsRef<Path>>(
|
||||
system_location: Option<P>,
|
||||
audio_location: Option<P>,
|
||||
credentials: Option<P>,
|
||||
volume: Option<P>,
|
||||
audio: 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 {
|
||||
fs::create_dir_all(location)?;
|
||||
}
|
||||
|
||||
let mut size_limiter = None;
|
||||
let credentials_location = credentials
|
||||
.as_ref()
|
||||
.map(|p| p.as_ref().join("credentials.json"));
|
||||
|
||||
if let Some(location) = &audio_location {
|
||||
if let Some(location) = &volume {
|
||||
fs::create_dir_all(location)?;
|
||||
}
|
||||
|
||||
let volume_location = volume.as_ref().map(|p| p.as_ref().join("volume"));
|
||||
|
||||
if let Some(location) = &audio {
|
||||
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.map(|p| p.as_ref().to_owned());
|
||||
|
||||
let cache = Cache {
|
||||
credentials_location,
|
||||
|
|
17
src/main.rs
17
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(
|
||||
|
@ -560,10 +562,11 @@ fn get_setup(args: &[String]) -> Setup {
|
|||
|
||||
let cache = {
|
||||
let audio_dir;
|
||||
let system_dir;
|
||||
let cred_dir;
|
||||
let volume_dir;
|
||||
if matches.opt_present(DISABLE_AUDIO_CACHE) {
|
||||
audio_dir = None;
|
||||
system_dir = matches
|
||||
volume_dir = matches
|
||||
.opt_str(SYSTEM_CACHE)
|
||||
.or_else(|| matches.opt_str(CACHE))
|
||||
.map(|p| p.into());
|
||||
|
@ -572,12 +575,18 @@ fn get_setup(args: &[String]) -> Setup {
|
|||
audio_dir = cache_dir
|
||||
.as_ref()
|
||||
.map(|p| AsRef::<Path>::as_ref(p).join("files"));
|
||||
system_dir = matches
|
||||
volume_dir = matches
|
||||
.opt_str(SYSTEM_CACHE)
|
||||
.or(cache_dir)
|
||||
.map(|p| p.into());
|
||||
}
|
||||
|
||||
if matches.opt_present(DISABLE_CREDENTIAL_CACHE) {
|
||||
cred_dir = None;
|
||||
} else {
|
||||
cred_dir = volume_dir.clone();
|
||||
}
|
||||
|
||||
let limit = if audio_dir.is_some() {
|
||||
matches
|
||||
.opt_str(CACHE_SIZE_LIMIT)
|
||||
|
@ -593,7 +602,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);
|
||||
|
|
Loading…
Reference in a new issue