diff options
Diffstat (limited to '')
-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() + ) + })?, + } + } } } |