diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-18 18:13:31 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-18 18:13:31 +0200 |
commit | ee48fa727afd1927f20b5d0491344f4afb03bd2e (patch) | |
tree | 9065db78bae252a3015f938471721aa418231b89 | |
parent | test(crates/yt/tests/_testenv): Store `Child`s instead of PIDs (diff) | |
download | yt-ee48fa727afd1927f20b5d0491344f4afb03bd2e.zip |
fix(crates/yt/db/insert/maintenance): Re-init
-rw-r--r-- | crates/yt/src/storage/db/insert/maintenance.rs | 28 | ||||
-rw-r--r-- | crates/yt/src/storage/db/insert/mod.rs | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/crates/yt/src/storage/db/insert/maintenance.rs b/crates/yt/src/storage/db/insert/maintenance.rs new file mode 100644 index 0000000..6442c48 --- /dev/null +++ b/crates/yt/src/storage/db/insert/maintenance.rs @@ -0,0 +1,28 @@ +use crate::{ + app::App, + storage::db::{ + insert::Operations, + video::{Video, VideoStatus, VideoStatusMarker}, + }, +}; + +use anyhow::Result; + +/// Remove the downloaded paths from videos in the db, that no longer exist on the file system. +pub(crate) async fn clear_stale_downloaded_paths(app: &App) -> Result<()> { + let mut cached_videos = Video::in_states(app, &[VideoStatusMarker::Cached]).await?; + + let mut ops = Operations::new("DbMaintain: init"); + for vid in &mut cached_videos { + if let VideoStatus::Cached { cache_path, .. } = &vid.status { + if !cache_path.exists() { + vid.remove_download_path(&mut ops); + } + } else { + unreachable!("We only asked for cached videos.") + } + } + ops.commit(app).await?; + + Ok(()) +} diff --git a/crates/yt/src/storage/db/insert/mod.rs b/crates/yt/src/storage/db/insert/mod.rs index f1d464f..e83287a 100644 --- a/crates/yt/src/storage/db/insert/mod.rs +++ b/crates/yt/src/storage/db/insert/mod.rs @@ -6,6 +6,7 @@ use anyhow::Result; use log::trace; use sqlx::SqliteConnection; +pub(crate) mod maintenance; pub(crate) mod playlist; pub(crate) mod subscription; pub(crate) mod video; |