mirror of
https://codeberg.org/icewind/galton.git
synced 2026-06-03 10:24:07 +02:00
skip empty files
This commit is contained in:
parent
30271f9a3d
commit
4c0ebc138d
1 changed files with 11 additions and 3 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -121,6 +121,10 @@ fn handle_watch_event(
|
|||
|
||||
match FileInfo::load(path) {
|
||||
Ok(file) => {
|
||||
if file.size == 0 {
|
||||
info!(file = file.path, "skipping empty file");
|
||||
return;
|
||||
}
|
||||
if let Some(new_path) = handle_file(&file, rules, remove_duplicates) {
|
||||
maybe_link_target(&new_path, link_target);
|
||||
if notify {
|
||||
|
|
@ -251,8 +255,6 @@ fn match_file(file: &FileInfo, rules: &[Rule]) -> Option<RuleResult> {
|
|||
#[instrument(skip_all, fields(file = file.path))]
|
||||
fn handle_file(file: &FileInfo, rules: &[Rule], remove_duplicates: bool) -> Option<PathBuf> {
|
||||
let Some(result) = match_file(file, rules) else {
|
||||
info!(url = file.url, "removing duplicate");
|
||||
|
||||
if remove_duplicates {
|
||||
let parent = Path::new(&file.path).parent().unwrap();
|
||||
if let Some(duplicate) = has_duplicate(file, parent) {
|
||||
|
|
@ -277,6 +279,7 @@ fn handle_file(file: &FileInfo, rules: &[Rule], remove_duplicates: bool) -> Opti
|
|||
|
||||
if remove_duplicates {
|
||||
if let Some(duplicate) = has_duplicate(file, parent) {
|
||||
dbg!(file.size);
|
||||
info!(url = file.url, diplicate = %duplicate.display(), "removing duplicate");
|
||||
if let Err(error) = remove_file(&file.path) {
|
||||
error!(%error, "failed to remove duplicate");
|
||||
|
|
@ -300,6 +303,11 @@ fn handle_file(file: &FileInfo, rules: &[Rule], remove_duplicates: bool) -> Opti
|
|||
}
|
||||
|
||||
fn has_duplicate(file: &FileInfo, dir: impl AsRef<Path>) -> Option<PathBuf> {
|
||||
if file.size == 0 {
|
||||
return None;
|
||||
}
|
||||
dbg!(file.size);
|
||||
|
||||
let dir = match read_dir(dir) {
|
||||
Ok(dir) => dir,
|
||||
Err(error) => {
|
||||
|
|
@ -312,7 +320,7 @@ fn has_duplicate(file: &FileInfo, dir: impl AsRef<Path>) -> Option<PathBuf> {
|
|||
if path.to_str() == Some(file.path.as_str()) {
|
||||
continue;
|
||||
}
|
||||
if !path.is_file() {
|
||||
if path.is_symlink() || !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue