Skip to content

Commit

Permalink
Merge pull request #221 from stepchowfun/v0.21.1
Browse files Browse the repository at this point in the history
Release v0.21.1
  • Loading branch information
stepchowfun authored Apr 13, 2022
2 parents 779dec3 + fc6f7ae commit 8e1d713
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docuum"
version = "0.21.0"
version = "0.21.1"
authors = ["Stephan Boyer <stephan@stephanboyer.com>"]
edition = "2021"
description = "LRU eviction of Docker images."
Expand All @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Threshold> {
match threshold.strip_suffix('%') {
Some(threshold) => {
Expand Down Expand Up @@ -87,6 +90,18 @@ impl Threshold {
.map(Threshold::Absolute),
}
}

#[cfg(not(target_os = "linux"))]
fn from_str(threshold: &str) -> io::Result<Threshold> {
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.
Expand Down
11 changes: 10 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -306,6 +310,7 @@ fn image_ids_in_use() -> io::Result<HashSet<String>> {
}

// Determine Docker's root directory.
#[cfg(target_os = "linux")]
fn docker_root_dir() -> io::Result<PathBuf> {
// Query Docker for it.
let output = Command::new("docker")
Expand All @@ -328,6 +333,7 @@ fn docker_root_dir() -> io::Result<PathBuf> {
}

// 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()
Expand All @@ -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<Byte> {
let root_dir = docker_root_dir()?;
let system = System::new_with_specifics(RefreshKind::new().with_disks_list());
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8e1d713

Please sign in to comment.