aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-05-11 20:39:27 -0500
committerToby Vincent <tobyv13@gmail.com>2022-05-11 20:39:27 -0500
commitbd0793b71f557049f252e0256297e0407c065bad (patch)
tree1b2439ac32935950aff6415a65bf2a42fa04fe2f
parent5a76a67cb28f7e6026bfacfd2d62269dc6fe1890 (diff)
feat: create default get_last_id impl in Volumes trait
-rw-r--r--zone_core/src/storage/volumes.rs10
-rw-r--r--zone_zfs/src/zfs.rs15
2 files changed, 14 insertions, 11 deletions
diff --git a/zone_core/src/storage/volumes.rs b/zone_core/src/storage/volumes.rs
index f310337..08e0104 100644
--- a/zone_core/src/storage/volumes.rs
+++ b/zone_core/src/storage/volumes.rs
@@ -8,4 +8,14 @@ pub trait Volumes {
fn list_volumes(&self) -> Result<Vec<Container>, Self::Error>;
fn get_volume(&self, container: &Container) -> Result<PathBuf, Self::Error>;
+
+ fn get_last_id(&self, template: &str, owner: &str) -> Result<u32, Self::Error> {
+ self.list_volumes().map(|v| {
+ v.into_iter()
+ .filter(|c| c.template == *template && c.owner == *owner)
+ .max_by_key(|c| c.id)
+ .map(|c| c.id)
+ .unwrap_or(0)
+ })
+ }
}
diff --git a/zone_zfs/src/zfs.rs b/zone_zfs/src/zfs.rs
index 98258a1..eabc2f8 100644
--- a/zone_zfs/src/zfs.rs
+++ b/zone_zfs/src/zfs.rs
@@ -25,16 +25,6 @@ impl ZFS {
.map_err(Error::from)
.map(|config| Self { config })
}
-
- fn get_last_id(&self, template: &str, owner: &str) -> Result<u32> {
- self.list_volumes()?
- .into_iter()
- .filter(|c| c.template == *template && c.owner == *owner)
- .max_by_key(|c| c.id)
- .map(|c| c.id)
- .ok_or(FileSystemError::NotFound)
- .map_err(Error::from)
- }
}
impl Volumes for ZFS {
@@ -69,7 +59,10 @@ impl Volumes for ZFS {
}
fn get_volume(&self, container: &Container) -> Result<PathBuf> {
- let fs = self.config.pool_name.join(PathBuf::from(container.to_owned()));
+ let fs = self
+ .config
+ .pool_name
+ .join(PathBuf::from(container.to_owned()));
let output = Command::new("zfs")
.arg("get")