fix: walkdir
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kieran 2025-02-12 11:23:31 +00:00
parent b6bd190252
commit f5b206dad3
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
4 changed files with 9 additions and 10 deletions

1
Cargo.lock generated
View File

@ -3213,6 +3213,7 @@ dependencies = [
"tokio", "tokio",
"tokio-util", "tokio-util",
"uuid", "uuid",
"walkdir",
] ]
[[package]] [[package]]

View File

@ -57,6 +57,7 @@ clap = { version = "4.5.18", features = ["derive"] }
mime2ext = "0.1.53" mime2ext = "0.1.53"
infer = "0.16.0" infer = "0.16.0"
tokio-util = { version = "0.7.13", features = ["io", "io-util"] } tokio-util = { version = "0.7.13", features = ["io", "io-util"] }
walkdir = "2.5.0"
libc = { version = "0.2.153", optional = true } libc = { version = "0.2.153", optional = true }
ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "a63b88ef3c8f58c7c0ac57d361d06ff0bb3ed385", optional = true } ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "a63b88ef3c8f58c7c0ac57d361d06ff0bb3ed385", optional = true }

View File

@ -51,12 +51,9 @@ async fn main() -> Result<(), Error> {
Commands::Check { delete } => { Commands::Check { delete } => {
info!("Checking files in: {}", settings.storage_dir); info!("Checking files in: {}", settings.storage_dir);
let fs = FileStore::new(settings.clone()); let fs = FileStore::new(settings.clone());
let mut dir = tokio::fs::read_dir(fs.storage_dir()).await?; let dir = walkdir::WalkDir::new(fs.storage_dir());
while let Some(entry) = dir.next_entry().await? { let dir = dir.into_iter().filter_map(Result::ok).filter(|f| f.file_type().is_file());
if entry.file_type().await?.is_dir() { for entry in dir {
continue;
}
let id = if let Ok(f) = hex::decode(entry.file_name().to_str().unwrap()) { let id = if let Ok(f) = hex::decode(entry.file_name().to_str().unwrap()) {
f f
} else { } else {
@ -64,7 +61,7 @@ async fn main() -> Result<(), Error> {
continue; continue;
}; };
let hash = FileStore::hash_file(&entry.path()).await?; let hash = FileStore::hash_file(entry.path()).await?;
if hash != id { if hash != id {
if delete.unwrap_or(false) { if delete.unwrap_or(false) {
warn!("Deleting corrupt file: {}", entry.path().display()); warn!("Deleting corrupt file: {}", entry.path().display());

View File

@ -14,7 +14,7 @@ use ffmpeg_rs_raw::DemuxerInfo;
use rocket::form::validate::Contains; use rocket::form::validate::Contains;
use serde::Serialize; use serde::Serialize;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use std::path::PathBuf; use std::path::{Path, PathBuf};
use tokio::fs::File; use tokio::fs::File;
use tokio::io::{AsyncRead, AsyncReadExt}; use tokio::io::{AsyncRead, AsyncReadExt};
use uuid::Uuid; use uuid::Uuid;
@ -232,7 +232,7 @@ impl FileStore {
Ok((out_path, n, hash)) Ok((out_path, n, hash))
} }
pub async fn hash_file(p: &PathBuf) -> Result<Vec<u8>, Error> { pub async fn hash_file(p: &Path) -> Result<Vec<u8>, Error> {
let mut file = File::open(p).await?; let mut file = File::open(p).await?;
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
let mut buf = [0; 4096]; let mut buf = [0; 4096];