This commit is contained in:
parent
b6bd190252
commit
f5b206dad3
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3213,6 +3213,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"uuid",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -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 }
|
||||
regex = { version = "1.11.1", optional = true }
|
||||
|
@ -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());
|
||||
|
@ -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<Vec<u8>, Error> {
|
||||
pub async fn hash_file(p: &Path) -> Result<Vec<u8>, Error> {
|
||||
let mut file = File::open(p).await?;
|
||||
let mut hasher = Sha256::new();
|
||||
let mut buf = [0; 4096];
|
||||
|
Loading…
x
Reference in New Issue
Block a user