Simple tool for automatic file management

ft(actions): add copy action

hauleth.dev 5064df15 8068c0e4

verified
Changed files
+22
examples
src
+14
examples/downloaded-gp-to-guitar.json
···
···
+
[
+
{
+
"location": "~/Downloads/",
+
"filter": {
+
"type": "any",
+
"filters": [
+
{"type": "name", "wildcard": "*.gp"}
+
]
+
},
+
"actions": [
+
{"move": "~/Documents/Guitar/"}
+
]
+
}
+
]
+8
src/actions.rs
···
Script(Box<Path>),
/// Move given file to new destination
Move(Box<Path>),
/// Print message and do nothing
Echo(String),
/// Move to trash
···
match self {
Action::Script(ref script) => println!("Execute {script:?} {source:?}"),
Action::Move(ref dest) => println!("Move {source:?} -> {dest:?}"),
Action::Echo(ref message) => println!("{source:?} - {message}"),
Action::Trash => println!("Move {source:?} to trash"),
}
···
.wait()
.await
.expect("Child exited abnormally");
}
Action::Move(ref dest_dir) => {
···
Script(Box<Path>),
/// Move given file to new destination
Move(Box<Path>),
+
/// Copy given file to new destination
+
Copy(Box<Path>),
/// Print message and do nothing
Echo(String),
/// Move to trash
···
match self {
Action::Script(ref script) => println!("Execute {script:?} {source:?}"),
Action::Move(ref dest) => println!("Move {source:?} -> {dest:?}"),
+
Action::Copy(ref dest) => println!("Copy {source:?} -> {dest:?}"),
Action::Echo(ref message) => println!("{source:?} - {message}"),
Action::Trash => println!("Move {source:?} to trash"),
}
···
.wait()
.await
.expect("Child exited abnormally");
+
}
+
+
Action::Copy(ref dest_dir) => {
+
let dest = crate::job::normalise_path(dest_dir).join(source.file_name().unwrap());
+
fs::copy(&source, dest).await.expect("Couldnt copy file");
}
Action::Move(ref dest_dir) => {