Skip to content

Commit

Permalink
only use cache if username matches
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Oct 2, 2022
1 parent 99c20d0 commit 00f52f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
15 changes: 5 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,11 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
let cache = config
.shared_config
.cache_path
.map(PathBuf::from)
// TODO: plumb size limits, check audio_cache?
// TODO: rather than silently disabling cache if constructor fails, maybe we should handle the error?
.and_then(|path| {
Cache::new(
Some(path.clone()),
if audio_cache { Some(path) } else { None },
size_limit,
)
.ok()
.map(|path| Cache::new(Some(&path), audio_cache.then_some(&path), size_limit))
.transpose()
.unwrap_or_else(|e| {
warn!("Cache couldn't be initialized: {e}");
None
});

let bitrate: LSBitrate = config
Expand Down
11 changes: 8 additions & 3 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ fn get_credentials(
username: &Option<String>,
password: &Option<String>,
) -> Option<Credentials> {
if let (Some(username), Some(password)) = (username, password) {
return Some(Credentials::with_password(username, password));
if let Some(credentials) = cache.as_ref().and_then(Cache::credentials) {
if username.as_ref() == Some(&credentials.username) {
return Some(credentials);
}
}

cache.as_ref()?.credentials()
Some(Credentials::with_password(
username.as_ref()?,
password.as_ref()?,
))
}

fn find_backend(name: Option<&str>) -> fn(Option<String>, AudioFormat) -> Box<dyn Sink> {
Expand Down

0 comments on commit 00f52f9

Please sign in to comment.