diff options
-rw-r--r-- | Cargo.lock | 27 | ||||
-rw-r--r-- | zone_zfs/Cargo.toml | 6 | ||||
-rw-r--r-- | zone_zfs/src/config.rs | 8 | ||||
-rw-r--r-- | zone_zfs/src/file_system.rs | 12 | ||||
-rw-r--r-- | zone_zfs/src/zfs.rs | 3 |
5 files changed, 31 insertions, 25 deletions
@@ -106,19 +106,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" [[package]] -name = "bytes" -version = "1.1.0" +name = "byte-unit" +version = "4.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "95ebf10dda65f19ff0f42ea15572a359ed60d7fc74fdc984d90310937be0014b" +dependencies = [ + "serde", + "utf8-width", +] [[package]] -name = "bytesize" +name = "bytes" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" -dependencies = [ - "serde", -] +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" @@ -385,8 +386,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" dependencies = [ "atomic", + "parking_lot", "pear", "serde", + "tempfile", "toml", "uncased", "version_check", @@ -2066,6 +2069,12 @@ dependencies = [ ] [[package]] +name = "utf8-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cf7d77f457ef8dfa11e4cd5933c5ddb5dc52a94664071951219a97710f0a32b" + +[[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2273,7 +2282,7 @@ dependencies = [ name = "zone_zfs" version = "0.1.0" dependencies = [ - "bytesize", + "byte-unit", "chrono", "derive_builder", "figment", diff --git a/zone_zfs/Cargo.toml b/zone_zfs/Cargo.toml index 5abefa3..241710a 100644 --- a/zone_zfs/Cargo.toml +++ b/zone_zfs/Cargo.toml @@ -5,11 +5,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bytesize = { version = "1.1.0", features = ["serde"] } +byte-unit = { version = "4.0.13", features = ["serde"], default-features = false } chrono = { version = "0.4.19", optional = true } derive_builder = "0.10.2" -figment = "0.10.6" -serde = "1.0.136" +figment = { version = "0.10.6", features = ["toml", "env", "test"] } +serde = { version = "1.0.136", features = ["derive"] } thiserror = "1.0.30" tracing = "0.1.29" diff --git a/zone_zfs/src/config.rs b/zone_zfs/src/config.rs index abe07ac..4c0a8b5 100644 --- a/zone_zfs/src/config.rs +++ b/zone_zfs/src/config.rs @@ -1,4 +1,4 @@ -use bytesize::ByteSize; +use byte_unit::Byte; use figment::{ error::Result, providers::{Env, Format, Serialized, Toml}, @@ -8,9 +8,9 @@ use figment::{ use serde::{Deserialize, Serialize}; use std::path::PathBuf; -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] pub struct Config { - pub quota: ByteSize, + pub quota: Byte, pub pool_name: String, pub mountpoint: PathBuf, } @@ -18,7 +18,7 @@ pub struct Config { impl Default for Config { fn default() -> Self { Config { - quota: ByteSize::gb(16), + quota: 16_000_000_000u64.into(), pool_name: String::from("pool"), mountpoint: PathBuf::from("/srv"), } diff --git a/zone_zfs/src/file_system.rs b/zone_zfs/src/file_system.rs index 62169d0..85bd6ca 100644 --- a/zone_zfs/src/file_system.rs +++ b/zone_zfs/src/file_system.rs @@ -1,5 +1,5 @@ use crate::{Error, Result, Snapshot}; -use bytesize::ByteSize; +use byte_unit::Byte; use derive_builder::Builder; use std::{ ffi::{OsStr, OsString}, @@ -26,7 +26,7 @@ macro_rules! concat_opt [ pub struct FileSystem { dataset: PathBuf, mountpoint: PathBuf, - quota: ByteSize, + quota: Byte, } impl Display for FileSystem { @@ -65,7 +65,7 @@ impl FileSystem { } /// Get the file system's quota. - pub fn quota(&self) -> ByteSize { + pub fn quota(&self) -> Byte { self.quota } @@ -104,7 +104,7 @@ impl FileSystem { }) } - pub fn set_quota(&mut self, quota: ByteSize) -> Result<Self> { + pub fn set_quota(&mut self, quota: Byte) -> Result<Self> { self.set_opt("quota", quota.to_string())?; self.quota = quota; Ok(self.to_owned()) @@ -116,10 +116,6 @@ impl FileSystem { Ok(self.to_owned()) } - pub fn get_mountpoint(&self) -> PathBuf { - self.mountpoint.to_owned() - } - pub fn get_snapshots(&self) -> Result<Vec<Snapshot>> { Command::new("zfs") .arg("list") diff --git a/zone_zfs/src/zfs.rs b/zone_zfs/src/zfs.rs index b1c4ed2..b24fe3a 100644 --- a/zone_zfs/src/zfs.rs +++ b/zone_zfs/src/zfs.rs @@ -51,6 +51,7 @@ impl ZFS { FileSystem::builder() .mountpoint(mountpoint) .dataset(dataset) + .quota(self.config.quota) .to_file_system() .ok() }) @@ -69,7 +70,7 @@ impl ZFS { #[cfg(test)] mod tests { #[test] - fn zfs_list() { + fn get_file_systems() { use super::*; assert!(ZFS::new().unwrap().get_file_systems().is_ok()); } |