feat: file dedup — content_hash SHA256 + /files/lookup API + auto-rename on name collision

This commit is contained in:
Accusys
2026-05-14 20:24:21 +08:00
parent 189bec929a
commit 4d1fe2d26f
5 changed files with 260 additions and 51 deletions

View File

@@ -0,0 +1,18 @@
use sha2::{Digest, Sha256};
use std::io::Read;
use std::path::Path;
use anyhow::Result;
/// Compute SHA256 of the entire file content
pub fn compute_sha256(path: &Path) -> Result<String> {
let mut file = std::fs::File::open(path)?;
let mut hasher = Sha256::new();
let mut buf = [0u8; 65536];
loop {
let n = file.read(&mut buf)?;
if n == 0 { break; }
hasher.update(&buf[..n]);
}
let hash = format!("{:x}", hasher.finalize());
Ok(hash)
}

View File

@@ -1,7 +1,9 @@
pub mod content_hash;
pub mod file_manager;
pub mod output_dir;
pub mod uuid;
pub use content_hash::compute_sha256;
pub use file_manager::FileManager;
pub use output_dir::OutputDir;
pub use uuid::compute_uuid;