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)]
13#[allow(clippy::doc_markdown)]
14pub struct ReplaceCancelCommand {
15 pub mount_point: PathBuf,
17}
18
19impl Runnable for ReplaceCancelCommand {
20 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
21 let file = open_path(&self.mount_point)?;
22
23 let was_running = replace_cancel(file.as_fd()).with_context(|| {
24 format!(
25 "failed to cancel replace on '{}'",
26 self.mount_point.display()
27 )
28 })?;
29
30 if was_running {
31 println!("replace cancelled on '{}'", self.mount_point.display());
32 } else {
33 println!("no replace operation was in progress");
34 }
35
36 Ok(())
37 }
38}