aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-02-07 23:02:54 -0600
committerToby Vincent <tobyv13@gmail.com>2022-02-07 23:02:54 -0600
commitfd85198b54103fbbfa38029610c2292e39f534bc (patch)
tree89eca530cf57a49f9f540fc72353bf1076d45421
parent7c54bd8f97ffd3b4196e22f52670b48a32229565 (diff)
feat: implement destroy, and mount/unmount
-rw-r--r--zone_zfs/src/file_system.rs45
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)),
+ }
+ }
}