2026-04-28 15:05:08 +02:00
|
|
|
use cosmic_files::operation::recursive::{Context, Method};
|
|
|
|
|
use cosmic_files::operation::{Controller, ReplaceResult};
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
use std::io;
|
|
|
|
|
use std::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);
|
|
|
|
|
})
|
2026-02-25 00:50:02 +02:00
|
|
|
.on_replace(|op, conflicting_count| {
|
2025-04-09 23:15:07 +02:00
|
|
|
Box::pin(async move {
|
2026-02-25 00:50:02 +02:00
|
|
|
println!(
|
|
|
|
|
"replace {:?}? (y/N) [conflicting: {}]",
|
|
|
|
|
op.to, conflicting_count
|
|
|
|
|
);
|
2025-04-09 23:15:07 +02:00
|
|
|
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"))],
|
2025-04-30 18:04:54 +01:00
|
|
|
Method::Copy,
|
2025-04-09 23:15:07 +02:00
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
context
|
|
|
|
|
.recursive_copy_or_move(
|
|
|
|
|
vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))],
|
2025-05-01 09:19:40 -06:00
|
|
|
Method::Move {
|
|
|
|
|
cross_device_copy: false,
|
|
|
|
|
},
|
2025-04-09 23:15:07 +02:00
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
2024-11-13 14:36:11 -07:00
|
|
|
Ok(())
|
|
|
|
|
}
|