use crate::{RunContext, Runnable, util::open_path};
use anyhow::{Context, Result};
use clap::Parser;
use std::{os::unix::io::AsFd, path::PathBuf};
#[derive(Parser, Debug)]
pub struct QuotaEnableCommand {
pub path: PathBuf,
#[clap(short = 's', long)]
pub simple: bool,
}
impl Runnable for QuotaEnableCommand {
fn run(&self, _ctx: &RunContext) -> Result<()> {
let file = open_path(&self.path)?;
btrfs_uapi::quota::quota_enable(file.as_fd(), self.simple)
.with_context(|| {
format!("failed to enable quota on '{}'", self.path.display())
})?;
if self.simple {
println!(
"quota enabled (simple mode) on '{}'",
self.path.display()
);
} else {
println!("quota enabled on '{}'", self.path.display());
}
Ok(())
}
}