diff --git a/Cargo.lock b/Cargo.lock index afa9b4f..2134116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3213,6 +3213,7 @@ dependencies = [ "tokio", "tokio-util", "uuid", + "walkdir", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d830e11..87e3c35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ clap = { version = "4.5.18", features = ["derive"] } mime2ext = "0.1.53" infer = "0.16.0" tokio-util = { version = "0.7.13", features = ["io", "io-util"] } +walkdir = "2.5.0" libc = { version = "0.2.153", optional = true } ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "a63b88ef3c8f58c7c0ac57d361d06ff0bb3ed385", optional = true } @@ -66,4 +67,4 @@ candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] } http-range-header = { version = "0.4.2", optional = true } nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr_backup_proc.git", branch = "main", optional = true } -regex = { version = "1.11.1", optional = true } \ No newline at end of file +regex = { version = "1.11.1", optional = true } diff --git a/src/bin/r96util.rs b/src/bin/r96util.rs index 02c0e65..7603dcb 100644 --- a/src/bin/r96util.rs +++ b/src/bin/r96util.rs @@ -51,12 +51,9 @@ async fn main() -> Result<(), Error> { Commands::Check { delete } => { info!("Checking files in: {}", settings.storage_dir); let fs = FileStore::new(settings.clone()); - let mut dir = tokio::fs::read_dir(fs.storage_dir()).await?; - while let Some(entry) = dir.next_entry().await? { - if entry.file_type().await?.is_dir() { - continue; - } - + let dir = walkdir::WalkDir::new(fs.storage_dir()); + let dir = dir.into_iter().filter_map(Result::ok).filter(|f| f.file_type().is_file()); + for entry in dir { let id = if let Ok(f) = hex::decode(entry.file_name().to_str().unwrap()) { f } else { @@ -64,7 +61,7 @@ async fn main() -> Result<(), Error> { continue; }; - let hash = FileStore::hash_file(&entry.path()).await?; + let hash = FileStore::hash_file(entry.path()).await?; if hash != id { if delete.unwrap_or(false) { warn!("Deleting corrupt file: {}", entry.path().display()); diff --git a/src/filesystem.rs b/src/filesystem.rs index a3993eb..f55a0d6 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -14,7 +14,7 @@ use ffmpeg_rs_raw::DemuxerInfo; use rocket::form::validate::Contains; use serde::Serialize; use sha2::{Digest, Sha256}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use tokio::fs::File; use tokio::io::{AsyncRead, AsyncReadExt}; use uuid::Uuid; @@ -232,7 +232,7 @@ impl FileStore { Ok((out_path, n, hash)) } - pub async fn hash_file(p: &PathBuf) -> Result, Error> { + pub async fn hash_file(p: &Path) -> Result, Error> { let mut file = File::open(p).await?; let mut hasher = Sha256::new(); let mut buf = [0; 4096];