diff --git a/CHANGELOG.md b/CHANGELOG.md index e0ca679..2eb472d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.21.1] - 2022-04-12 + +### Fixed +- Fixed an issue introduced in v0.21.0 which prevented Docuum from working on Windows. + ## [0.21.0] - 2022-04-05 ### Added diff --git a/Cargo.lock b/Cargo.lock index b826ad3..32c0aea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ dependencies = [ [[package]] name = "docuum" -version = "0.21.0" +version = "0.21.1" dependencies = [ "atty", "byte-unit", diff --git a/Cargo.toml b/Cargo.toml index 610546d..03c79f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "docuum" -version = "0.21.0" +version = "0.21.1" authors = ["Stephan Boyer "] edition = "2021" description = "LRU eviction of Docker images." @@ -23,6 +23,8 @@ serde_json = "1.0" serde_yaml = "0.8" tempfile = "3" regex = "1.5.4" + +[target.'cfg(target_os = "linux")'.dependencies] sysinfo = "0.23.5" [dependencies.clap] diff --git a/src/main.rs b/src/main.rs index 5c9e3c3..0dd3bf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,11 +41,14 @@ const KEEP_OPTION: &str = "keep"; #[derive(Copy, Clone)] enum Threshold { Absolute(Byte), + + #[cfg(target_os = "linux")] Percentage(f64), } impl Threshold { // Parse a `Threshold`. Relative thresholds are only supported on Linux. + #[cfg(target_os = "linux")] fn from_str(threshold: &str) -> io::Result { match threshold.strip_suffix('%') { Some(threshold) => { @@ -87,6 +90,18 @@ impl Threshold { .map(Threshold::Absolute), } } + + #[cfg(not(target_os = "linux"))] + fn from_str(threshold: &str) -> io::Result { + Byte::from_str(threshold) + .map_err(|_| { + io::Error::new( + io::ErrorKind::InvalidInput, + format!("Invalid absolute threshold {}.", threshold.code_str()), + ) + }) + .map(Threshold::Absolute) + } } // This struct represents the command-line arguments. diff --git a/src/run.rs b/src/run.rs index 6324c8b..74368c6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -15,10 +15,14 @@ use { io::{self, BufRead, BufReader}, mem::drop, ops::Deref, - path::{Path, PathBuf}, process::{Command, Stdio}, time::{Duration, SystemTime, UNIX_EPOCH}, }, +}; + +#[cfg(target_os = "linux")] +use { + std::path::{Path, PathBuf}, sysinfo::{Disk, DiskExt, RefreshKind, System, SystemExt}, }; @@ -306,6 +310,7 @@ fn image_ids_in_use() -> io::Result> { } // Determine Docker's root directory. +#[cfg(target_os = "linux")] fn docker_root_dir() -> io::Result { // Query Docker for it. let output = Command::new("docker") @@ -328,6 +333,7 @@ fn docker_root_dir() -> io::Result { } // Find the disk containing a path. +#[cfg(target_os = "linux")] fn get_disk_by_file<'a>(disks: &'a [Disk], path: &Path) -> io::Result<&'a Disk> { disks .iter() @@ -345,6 +351,7 @@ fn get_disk_by_file<'a>(disks: &'a [Disk], path: &Path) -> io::Result<&'a Disk> } // Find size of filesystem on which docker root directory is stored. +#[cfg(target_os = "linux")] fn docker_root_dir_filesystem_size() -> io::Result { let root_dir = docker_root_dir()?; let system = System::new_with_specifics(RefreshKind::new().with_disks_list()); @@ -726,6 +733,8 @@ pub fn run(settings: &Settings, state: &mut State, first_run: &mut bool) -> io:: // Determine the threshold in bytes. let threshold = match settings.threshold { Threshold::Absolute(b) => b, + + #[cfg(target_os = "linux")] Threshold::Percentage(p) => { #[allow(