btrfs_cli/filesystem/
sync.rs1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use btrfs_uapi::filesystem::sync;
4use clap::Parser;
5use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
6
7#[derive(Parser, Debug)]
9pub struct FilesystemSyncCommand {
10 pub path: PathBuf,
11}
12
13impl Runnable for FilesystemSyncCommand {
14 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
15 let file = File::open(&self.path).with_context(|| {
16 format!("failed to open '{}'", self.path.display())
17 })?;
18 sync(file.as_fd()).with_context(|| {
19 format!("failed to sync '{}'", self.path.display())
20 })?;
21 Ok(())
22 }
23}