mirror of
https://codeberg.org/icewind/galton.git
synced 2026-06-03 10:24:07 +02:00
readme stub
This commit is contained in:
parent
1269e95b6f
commit
9460fa8cab
3 changed files with 28 additions and 17 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "galton"
|
name = "galton"
|
||||||
description = "Sort your incoming files"
|
description = "Let your downloads into the right place"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.85.0"
|
rust-version = "1.85.0"
|
||||||
|
|
|
||||||
3
README.md
Normal file
3
README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Galton
|
||||||
|
|
||||||
|
Let your downloads into the right place
|
||||||
40
src/main.rs
40
src/main.rs
|
|
@ -105,22 +105,7 @@ fn handle_watch_event(result: DebounceEventResult, rules: &[Rule], link_target:
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
match FileInfo::load(path) {
|
match FileInfo::load(path) {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
if let Some(target) = handle_file(&file, rules) {
|
maybe_link(handle_file(&file, rules).as_deref(), link_target)
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
error!(%error, "failed to load file info");
|
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> {
|
fn match_file(file: &FileInfo, rules: &[Rule]) -> Option<RuleMatch> {
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
if let Some(result) = rule.matches(file) {
|
if let Some(result) = rule.matches(file) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue