btrfs_cli/replace/
cancel.rs1use crate::{Format, Runnable, util::open_path};
2use anyhow::{Context, Result};
3use btrfs_uapi::replace::replace_cancel;
4use clap::Parser;
5use std::{os::unix::io::AsFd, path::PathBuf};
6
7#[derive(Parser, Debug)]
13pub struct ReplaceCancelCommand {
14 pub mount_point: PathBuf,
16}
17
18impl Runnable for ReplaceCancelCommand {
19 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
20 let file = open_path(&self.mount_point)?;
21
22 let was_running = replace_cancel(file.as_fd()).with_context(|| {
23 format!(
24 "failed to cancel replace on '{}'",
25 self.mount_point.display()
26 )
27 })?;
28
29 if was_running {
30 println!("replace cancelled on '{}'", self.mount_point.display());
31 } else {
32 println!("no replace operation was in progress");
33 }
34
35 Ok(())
36 }
37}