mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Fix audio file caching
This commit is contained in:
parent
3e09eff906
commit
5c2b5a21c1
2 changed files with 4 additions and 4 deletions
|
@ -336,7 +336,7 @@ impl AudioFile {
|
|||
debug!("Downloading file {} complete", file_id);
|
||||
|
||||
if let Some(cache) = session_.cache() {
|
||||
if let Some(cache_id) = cache.file(file_id) {
|
||||
if let Some(cache_id) = cache.file_path(file_id) {
|
||||
if let Err(e) = cache.save_file(file_id, &mut file) {
|
||||
error!("Error caching file {} to {:?}: {}", file_id, cache_id, e);
|
||||
} else {
|
||||
|
|
|
@ -367,7 +367,7 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
fn file_path(&self, file: FileId) -> Option<PathBuf> {
|
||||
pub fn file_path(&self, file: FileId) -> Option<PathBuf> {
|
||||
self.audio_location.as_ref().map(|location| {
|
||||
let name = file.to_base16();
|
||||
let mut path = location.join(&name[0..2]);
|
||||
|
@ -396,7 +396,7 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn save_file<F: Read>(&self, file: FileId, contents: &mut F) -> Result<(), Error> {
|
||||
pub fn save_file<F: Read>(&self, file: FileId, contents: &mut F) -> Result<PathBuf, Error> {
|
||||
if let Some(path) = self.file_path(file) {
|
||||
if let Some(parent) = path.parent() {
|
||||
if let Ok(size) = fs::create_dir_all(parent)
|
||||
|
@ -407,7 +407,7 @@ impl Cache {
|
|||
limiter.add(&path, size);
|
||||
limiter.prune()?;
|
||||
}
|
||||
return Ok(());
|
||||
return Ok(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue