diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-10-19 14:26:28 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-10-19 14:26:28 +0200 |
commit | dd1d471820251dc9c5f60a5508e0e80711fb221a (patch) | |
tree | f400cc4d22736945c56dd3a302577df29cba0c96 | |
parent | fix(yt/download): Create the download dir, if it does not exist (diff) | |
download | yt-dd1d471820251dc9c5f60a5508e0e80711fb221a.tar.gz yt-dd1d471820251dc9c5f60a5508e0e80711fb221a.zip |
fix(yt/cache): Don't try to delete video cache paths that don't exist anymore
This is a quite common problem, because the download dir (residing on `/tmp/yt` by default) is cleared with every reboot, leaving the stale `cache_path` entries in the database. If a user would than run `yt download --force` these already deleted `cache_paths` should not be deleted again.
-rw-r--r-- | yt/src/cache/mod.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/yt/src/cache/mod.rs b/yt/src/cache/mod.rs index 6ceef25..dfbc276 100644 --- a/yt/src/cache/mod.rs +++ b/yt/src/cache/mod.rs @@ -9,7 +9,7 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use anyhow::{Context, Result}; -use log::info; +use log::{debug, info}; use tokio::fs; use crate::{ @@ -26,13 +26,25 @@ async fn invalidate_video(app: &App, video: &Video, hard: bool) -> Result<()> { if hard { if let Some(path) = &video.cache_path { info!("Removing cached video at: '{}'", path.display()); - fs::remove_file(path).await.with_context(|| { - format!( - "Failed to delete video ('{}') cache path: '{}'.", - video.title, - path.display() - ) - })?; + if let Err(err) = fs::remove_file(path).await.map_err(|err| err.kind()) { + match err { + std::io::ErrorKind::NotFound => { + // The path is already gone + debug!( + "Not actually removing path: '{}'. \ + It is already gone.", + path.display() + ); + } + err => Err(std::io::Error::from(err)).with_context(|| { + format!( + "Failed to delete video ('{}') cache path: '{}'.", + video.title, + path.display() + ) + })?, + } + } } } |