aboutsummaryrefslogtreecommitdiffstats
path: root/zone_zfs/src/snapshot.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-02-17 22:55:33 -0600
committerToby Vincent <tobyv13@gmail.com>2022-02-17 22:55:33 -0600
commit22039b683f3c111e42c9eb212c45d304b9c8ac10 (patch)
treec6de813929f40f228b056ce7d55ae2ade0a27809 /zone_zfs/src/snapshot.rs
parent239cf15875b88281873d0b443c288e4906733579 (diff)
refactor(zone_zfs): convert zfs crate to singleton
Refactored the zone_zfs to be a singleton with a psudo-builder pattern rocket is now managing the singleton, instead of the config.
Diffstat (limited to 'zone_zfs/src/snapshot.rs')
-rw-r--r--zone_zfs/src/snapshot.rs29
1 files changed, 7 insertions, 22 deletions
diff --git a/zone_zfs/src/snapshot.rs b/zone_zfs/src/snapshot.rs
index 14fafb4..b0fabb9 100644
--- a/zone_zfs/src/snapshot.rs
+++ b/zone_zfs/src/snapshot.rs
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use std::{ffi::OsString, path::PathBuf, process::Command};
use tracing::warn;
-use crate::{file_system::FileSystem, Error, Result};
+use crate::{error::Error, error::Result, file_system::FileSystem, Config};
#[derive(Debug)]
pub struct Snapshot {
@@ -38,32 +38,17 @@ impl TryFrom<&str> for Snapshot {
}
impl Snapshot {
- pub fn clone_into_file_system(
- &self,
- name: String,
- mountpoint: Option<PathBuf>,
- ) -> Result<FileSystem> {
- let new_fs = FileSystem {
- value: PathBuf::from(&self.file_system.value).join(name).into(),
- mountpoint,
- };
+ pub fn clone_into_file_system(&self, new_fs: PathBuf) -> Result<FileSystem> {
+ let mut file_system = self.file_system.clone();
+ file_system.value.push(&new_fs);
- let mut command = Command::new("zfs");
-
- command.arg("clone");
-
- if let Some(mp) = &new_fs.mountpoint {
- command
- .arg("-o")
- .arg(format!("mountpoint={}", mp.to_string_lossy()));
- };
-
- command
+ Command::new("zfs")
+ .arg("clone")
.arg(&self.value)
.arg(&new_fs)
.status()?
.success()
- .then(|| new_fs)
+ .then(|| file_system)
.ok_or_else(|| Error::Snapshot(format!("Failed to clone snapshot: {:?}", self)))
}
}