2024-11-19 08:15:47 -07:00
|
|
|
use cosmic_files::operation::{recursive::Context, Controller, ReplaceResult};
|
2024-11-13 14:47:35 -07:00
|
|
|
use std::{error::Error, io, path::PathBuf};
|
2024-11-13 14:36:11 -07:00
|
|
|
|
2025-04-09 23:15:07 +02:00
|
|
|
#[compio::main]
|
|
|
|
|
async fn main() -> Result<(), Box<dyn Error>> {
|
2025-01-19 01:05:02 -05:00
|
|
|
let mut context = Context::new(Controller::default())
|
2024-11-13 14:36:11 -07:00
|
|
|
.on_progress(|op, progress| {
|
|
|
|
|
println!("{:?}: {:?}", op.to, progress);
|
|
|
|
|
})
|
|
|
|
|
.on_replace(|op| {
|
2025-04-09 23:15:07 +02:00
|
|
|
Box::pin(async move {
|
|
|
|
|
println!("replace {:?}? (y/N)", op.to);
|
|
|
|
|
let mut line = String::new();
|
|
|
|
|
match io::stdin().read_line(&mut line) {
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
if line == "y" {
|
|
|
|
|
ReplaceResult::Replace(false)
|
|
|
|
|
} else {
|
|
|
|
|
ReplaceResult::Skip(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(err) => {
|
|
|
|
|
eprintln!("failed to read stdin: {}", err);
|
|
|
|
|
ReplaceResult::Cancel
|
2024-11-13 14:36:11 -07:00
|
|
|
}
|
|
|
|
|
}
|
2025-04-09 23:15:07 +02:00
|
|
|
})
|
2024-11-13 14:36:11 -07:00
|
|
|
});
|
|
|
|
|
|
2025-04-09 23:15:07 +02:00
|
|
|
context
|
|
|
|
|
.recursive_copy_or_move(
|
|
|
|
|
vec![(PathBuf::from("test/a"), PathBuf::from("test/b"))],
|
|
|
|
|
false,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
context
|
|
|
|
|
.recursive_copy_or_move(
|
|
|
|
|
vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))],
|
|
|
|
|
true,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
2024-11-13 14:36:11 -07:00
|
|
|
Ok(())
|
|
|
|
|
}
|