Skip to content

Commit

Permalink
Added dry-run mode command line option (-n, --dry-run).
Browse files Browse the repository at this point in the history
When invoked, Docuum will report what images would have been deleted
during it's initial vacuuming run at start up then exit.

In order to do this, Docuum now creates a list of images to delete
ensuring that by deleting them it will meet the space requirements set
forth by the user.
  • Loading branch information
mardambey committed Jan 9, 2024
1 parent 6020744 commit beb9c7d
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 45 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ OPTIONS:
-d, --deletion-chunk-size <DELETION CHUNK SIZE>
Removes specified quantity of images at a time (default: 1)
-n, --dry-run
Dry run mode, prevents deletion of any images.
-h, --help
Prints help information
Expand Down
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const DEFAULT_THRESHOLD: &str = "10 GB";
// Command-line argument and option names
const DELETION_CHUNK_SIZE_OPTION: &str = "deletion-chunk-size";
const KEEP_OPTION: &str = "keep";
const DRY_RUN_OPTION: &str = "dry-run";
const THRESHOLD_OPTION: &str = "threshold";

// Size threshold argument, absolute or relative to filesystem size
Expand Down Expand Up @@ -109,6 +110,7 @@ pub struct Settings {
threshold: Threshold,
keep: Option<RegexSet>,
deletion_chunk_size: usize,
dry_run: bool,
}

// Set up the logger.
Expand Down Expand Up @@ -186,6 +188,14 @@ fn settings() -> io::Result<Settings> {
.number_of_values(1)
.help("Prevents deletion of images for which repository:tag matches <REGEX>"),
)
.arg(
Arg::with_name(DRY_RUN_OPTION)
.short("n")
.long(DRY_RUN_OPTION)
.required(false)
.takes_value(false)
.help("Dry run mode, prevents deletion of any images."),
)
.arg(
Arg::with_name(DELETION_CHUNK_SIZE_OPTION)
.value_name("DELETION CHUNK SIZE")
Expand Down Expand Up @@ -216,6 +226,11 @@ fn settings() -> io::Result<Settings> {
None => None,
};

let dry_run = matches.is_present(DRY_RUN_OPTION);
if dry_run {
info!("Dry-run mode enabled, will not be deleting images.");
}

// Determine how many images to delete at once.
let deletion_chunk_size = match matches.value_of(DELETION_CHUNK_SIZE_OPTION) {
Some(v) => match v.parse::<usize>() {
Expand All @@ -229,6 +244,7 @@ fn settings() -> io::Result<Settings> {
threshold,
keep,
deletion_chunk_size,
dry_run,
})
}

Expand Down
Loading

0 comments on commit beb9c7d

Please sign in to comment.