From fd85198b54103fbbfa38029610c2292e39f534bc Mon Sep 17 00:00:00 2001 From: Neil Kollack Date: Mon, 7 Feb 2022 23:02:54 -0600 Subject: feat: implement destroy, and mount/unmount --- zone_zfs/src/file_system.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/zone_zfs/src/file_system.rs b/zone_zfs/src/file_system.rs index 7c9c6ab..2d3457f 100644 --- a/zone_zfs/src/file_system.rs +++ b/zone_zfs/src/file_system.rs @@ -102,7 +102,7 @@ impl FileSystem { .into_owned()) } - pub fn set_quota(&self, quota: &str) -> Result<()> { + pub(super) fn set_quota(&self, quota: &str) -> Result<()> { match Command::new("zfs") .arg("set") .arg(format!("quota={}", quota)) @@ -155,4 +155,47 @@ impl FileSystem { .map(|fs| fs.try_into()) .collect() } + + pub(super) fn mount_filesystem(&self) -> Result<()> { + match Command::new("zfs") + .arg("mount") + .arg(&self.value) + .status()? + .success() + { + true => Ok(()), + false => Err(anyhow!("Failed to mount the filesystem: {:?}", self)), + } + } + + pub(super) fn unmount_filesystem(&self) -> Result<()> { + match Command::new("zfs") + .arg("unmount") + .arg(&self.value) + .status()? + .success() + { + true => Ok(()), + false => Err(anyhow!("Failed to unmount the filesystem: {:?}", self)), + } + } + + pub(super) fn destroy_filesystem(&self, force: bool) -> Result<()> { + let mut args: Vec<&OsStr> = Vec::new(); + let f_arg = &OsString::from("-f"); + if force { + args.push(f_arg); + } + args.push(&self.value); + + match Command::new("zfs") + .arg("destroy") + .args(args) + .status()? + .success() + { + true => Ok(()), + false => Err(anyhow!("Failed to destroy the filesystem: {:?}", self)), + } + } } -- cgit v1.2.3-70-g09d2