1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-05 02:39:53 +02:00

Made locations in cache optional

The locations of credentials, volume and audio are now stored
in three separate Optional<PathBuf>s.
Removed the clearing of the cache if an error occurs. This might
be added again later.
This commit is contained in:
johannesd3 2021-01-25 02:22:25 +01:00
parent 14a004f84c
commit fa5c9f7d11
3 changed files with 108 additions and 117 deletions

View file

@ -5,7 +5,7 @@ use sha1::{Digest, Sha1};
use std::env;
use std::io::{self, stderr, Write};
use std::mem;
use std::path::PathBuf;
use std::path::Path;
use std::process::exit;
use std::str::FromStr;
use std::time::Instant;
@ -254,22 +254,32 @@ fn setup(args: &[String]) -> Setup {
mapped_volume: !matches.opt_present("mixer-linear-volume"),
};
let use_audio_cache = !matches.opt_present("disable-audio-cache");
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("c"))
.map(|p| p.into());
} else {
let cache_dir = matches.opt_str("c");
audio_dir = cache_dir
.as_ref()
.map(|p| AsRef::<Path>::as_ref(p).join("files"));
system_dir = matches
.opt_str("system-cache")
.or_else(|| cache_dir)
.map(|p| p.into());
}
let cache_directory = matches.opt_str("c").unwrap_or(String::from(""));
let system_cache_directory = matches
.opt_str("system-cache")
.unwrap_or(String::from(cache_directory.clone()));
let cache = match Cache::new(
PathBuf::from(cache_directory),
PathBuf::from(system_cache_directory),
use_audio_cache,
) {
Ok(cache) => Some(cache),
Err(e) => {
warn!("Cannot create cache: {}", e);
None
match Cache::new(system_dir, audio_dir) {
Ok(cache) => Some(cache),
Err(e) => {
warn!("Cannot create cache: {}", e);
None
}
}
};