Fix audio file caching

This commit is contained in:
Roderick van Domburg 2022-01-05 16:43:46 +01:00
parent 3e09eff906
commit 5c2b5a21c1
No known key found for this signature in database
GPG key ID: A9EF5222A26F0451
2 changed files with 4 additions and 4 deletions

View file

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

View file

@ -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);
}
}
}