readme stub

This commit is contained in:
Robin Appelman 2025-10-13 18:45:53 +02:00
commit 9460fa8cab
3 changed files with 28 additions and 17 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "galton"
description = "Sort your incoming files"
description = "Let your downloads into the right place"
version = "0.1.0"
edition = "2024"
rust-version = "1.85.0"

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# Galton
Let your downloads into the right place

View file

@ -105,22 +105,7 @@ fn handle_watch_event(result: DebounceEventResult, rules: &[Rule], link_target:
sleep(Duration::from_millis(200));
match FileInfo::load(path) {
Ok(file) => {
if let Some(target) = handle_file(&file, rules) {
if let Some(link_target) = link_target {
match symlink(&target, link_target) {
Ok(()) => {
info!(
to = target,
from = link_target,
"created symlink"
);
}
Err(error) => {
error!(%error, "failed to link target");
}
}
}
}
maybe_link(handle_file(&file, rules).as_deref(), link_target)
}
Err(error) => {
error!(%error, "failed to load file info");
@ -138,6 +123,29 @@ fn handle_watch_event(result: DebounceEventResult, rules: &[Rule], link_target:
}
}
fn maybe_link(source: Option<&str>, target: Option<&str>) {
if let (Some(source), Some(target)) = (source, target) {
if Path::new(target).exists() {
if let Err(error) = remove_file(target) {
error!(%error, "failed to remove link target");
return;
}
}
match symlink(source, target) {
Ok(()) => {
info!(
to = target,
from = source,
"created symlink"
);
}
Err(error) => {
error!(%error, "failed to link target");
}
}
}
}
fn match_file(file: &FileInfo, rules: &[Rule]) -> Option<RuleMatch> {
for rule in rules {
if let Some(result) = rule.matches(file) {