diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-02-07 23:02:54 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-02-07 23:02:54 -0600 |
commit | fd85198b54103fbbfa38029610c2292e39f534bc (patch) | |
tree | 89eca530cf57a49f9f540fc72353bf1076d45421 /zone_zfs/src | |
parent | 7c54bd8f97ffd3b4196e22f52670b48a32229565 (diff) |
feat: implement destroy, and mount/unmount
Diffstat (limited to 'zone_zfs/src')
-rw-r--r-- | zone_zfs/src/file_system.rs | 45 |
1 files changed, 44 insertions, 1 deletions
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)), + } + } } |