aboutsummaryrefslogtreecommitdiffstats
path: root/zone_zfs/src/zfs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zone_zfs/src/zfs.rs')
-rw-r--r--zone_zfs/src/zfs.rs42
1 files changed, 27 insertions, 15 deletions
diff --git a/zone_zfs/src/zfs.rs b/zone_zfs/src/zfs.rs
index c820c1c..0ffba13 100644
--- a/zone_zfs/src/zfs.rs
+++ b/zone_zfs/src/zfs.rs
@@ -20,15 +20,11 @@ impl ZFS {
.map(|config| Self { config })
}
- pub fn clone_from_latest(&self, name: PathBuf, parent: PathBuf) -> Result<FileSystem> {
- Self::get_file_system(parent)?
- .get_latest_snapshot()?
- .ok_or_else(|| Error::Snapshot("No snapshot found".into()))?
- .clone_into_file_system(name)?
- .set_quota(self.config.quota)
+ pub fn clone_from_latest(&self, _name: PathBuf, _parent: PathBuf) -> Result<FileSystem> {
+ todo!("implement using feature")
}
- pub(super) fn get_file_systems() -> Result<Vec<FileSystem>> {
+ pub fn get_file_systems(&self) -> Result<Vec<FileSystem>> {
Command::new("zfs")
.arg("list")
.arg("-H")
@@ -36,16 +32,32 @@ impl ZFS {
.arg("name")
.output()
.map(|o| String::from_utf8(o.stdout))?
- .map_err(Error::from)?
- .split_whitespace()
- .map(FileSystem::try_from)
- .collect()
+ .map_err(Error::from)
+ .map(|s| {
+ s.lines()
+ .into_iter()
+ .filter_map(|l| l.split_once(" ").map(|s| (s.0.trim(), s.1.trim())))
+ .filter_map(|(dataset, mountpoint)| {
+ let mountpoint = if mountpoint == "none" {
+ PathBuf::from(mountpoint)
+ } else {
+ self.config.mountpoint.to_owned()
+ };
+
+ FileSystem::builder()
+ .mountpoint(mountpoint)
+ .dataset(dataset)
+ .to_file_system()
+ .ok()
+ })
+ .collect()
+ })
}
- fn get_file_system(name: PathBuf) -> Result<FileSystem> {
- Self::get_file_systems()?
+ pub fn get_file_system(&self, name: PathBuf) -> Result<FileSystem> {
+ self.get_file_systems()?
.into_iter()
- .find(|fs| PathBuf::from(&fs.value).ends_with(&name))
+ .find(|fs| fs.dataset().ends_with(&name))
.ok_or_else(|| Error::FileSystem("No file system found".into()))
}
}
@@ -55,6 +67,6 @@ mod tests {
#[test]
fn zfs_list() {
use super::*;
- assert!(ZFS::get_file_systems().is_ok());
+ assert!(ZFS::new().unwrap().get_file_systems().is_ok());
}
}