Expand description
libxcp
is a high-level file-copy engine. It has a support for
multi-threading, fine-grained progress feedback, pluggable
drivers, and .gitignore
filters. libxcp
is the core
functionality of the xcp command-line utility.
§Usage example
use libxcp::config::Config;
use libxcp::errors::XcpError;
use libxcp::feedback::{ChannelUpdater, StatusUpdater, StatusUpdate};
use libxcp::drivers::{Drivers, load_driver};
let sources = vec![PathBuf::from("src")];
let dest = TempDir::new()?;
let config = Arc::new(Config::default());
let updater = ChannelUpdater::new(&config);
// The ChannelUpdater is consumed by the driver (so it is properly closed
// on completion). Retrieve our end of the connection before then.
let stat_rx = updater.rx_channel();
let stats: Arc<dyn StatusUpdater> = Arc::new(updater);
let driver = load_driver(Drivers::ParFile, &config)?;
// As we want realtime updates via the ChannelUpdater the
// copy operation should run in the background.
let handle = thread::spawn(move || {
driver.copy(sources, dest.path(), stats)
});
// Gather the results as we go; our end of the channel has been
// moved to the driver call and will end when drained.
for stat in stat_rx {
match stat {
StatusUpdate::Copied(v) => {
println!("Copied {} bytes", v);
},
StatusUpdate::Size(v) => {
println!("Size update: {}", v);
},
StatusUpdate::Error(e) => {
panic!("Error during copy: {}", e);
}
}
}
handle.join()
.map_err(|_| XcpError::CopyError("Error during copy operation".to_string()))??;
println!("Copy complete");
Modules§
- Driver configuration support.
- Support for pluggable copy drivers.
- Custom error types.
- Support for runtime feedback of copy progress.