From 2aca80ddf7dd899758261f870d6ac145130cb9dd Mon Sep 17 00:00:00 2001 From: Torben Giesselmann Date: Sun, 23 Apr 2023 13:56:15 -0700 Subject: [PATCH] forget: Interpret '--keep-* -1' as 'keep all' --- changelog/new.txt | 1 + src/commands/forget.rs | 54 ++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/changelog/new.txt b/changelog/new.txt index 200fa7f..ef9816a 100644 --- a/changelog/new.txt +++ b/changelog/new.txt @@ -9,6 +9,7 @@ Bugs fixed: New features: - backup: Backing up (small) files is now much more parallelized. +- forget: Using "-1" as value for --keep-* options will keep all snapshots of that interval - prune: Added option --repack-all - Option --dry-run is now a global option and can also be defined in the config file or via env variable - Updated to clap v4 diff --git a/src/commands/forget.rs b/src/commands/forget.rs index d1f7c40..5f4fa4a 100644 --- a/src/commands/forget.rs +++ b/src/commands/forget.rs @@ -175,45 +175,45 @@ pub(super) struct KeepOptions { #[merge(strategy=merge::vec::overwrite_empty)] keep_ids: Vec, - /// Keep the last N snapshots - #[clap(long, short = 'l', value_name = "N", default_value = "0")] + /// Keep the last N snapshots (N == -1: keep all snapshots) + #[clap(long, short = 'l', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_last: u32, + keep_last: i32, - /// Keep the last N hourly snapshots - #[clap(long, short = 'H', value_name = "N", default_value = "0")] + /// Keep the last N hourly snapshots (N == -1: keep all hourly snapshots) + #[clap(long, short = 'H', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_hourly: u32, + keep_hourly: i32, - /// Keep the last N daily snapshots - #[clap(long, short = 'd', value_name = "N", default_value = "0")] + /// Keep the last N daily snapshots (N == -1: keep all daily snapshots) + #[clap(long, short = 'd', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_daily: u32, + keep_daily: i32, - /// Keep the last N weekly snapshots - #[clap(long, short = 'w', value_name = "N", default_value = "0")] + /// Keep the last N weekly snapshots (N == -1: keep all weekly snapshots) + #[clap(long, short = 'w', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_weekly: u32, + keep_weekly: i32, - /// Keep the last N monthly snapshots - #[clap(long, short = 'm', value_name = "N", default_value = "0")] + /// Keep the last N monthly snapshots (N == -1: keep all monthly snapshots) + #[clap(long, short = 'm', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_monthly: u32, + keep_monthly: i32, - /// Keep the last N quarter-yearly snapshots - #[clap(long, value_name = "N", default_value = "0")] + /// Keep the last N quarter-yearly snapshots (N == -1: keep all quarter-yearly snapshots) + #[clap(long, value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_quarter_yearly: u32, + keep_quarter_yearly: i32, - /// Keep the last N half-yearly snapshots - #[clap(long, value_name = "N", default_value = "0")] + /// Keep the last N half-yearly snapshots (N == -1: keep all half-yearly snapshots) + #[clap(long, value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_half_yearly: u32, + keep_half_yearly: i32, - /// Keep the last N yearly snapshots - #[clap(long, short = 'y', value_name = "N", default_value = "0")] + /// Keep the last N yearly snapshots (N == -1: keep all yearly snapshots) + #[clap(long, short = 'y', value_name = "N", default_value = "0", allow_hyphen_values = true, value_parser = clap::value_parser!(i32).range(-1..))] #[merge(strategy=merge::num::overwrite_zero)] - keep_yearly: u32, + keep_yearly: i32, /// Keep snapshots newer than DURATION relative to latest snapshot #[clap(long, value_name = "DURATION", default_value = "0h")] @@ -404,10 +404,12 @@ impl KeepOptions { for (check_fun, counter, reason1, within, reason2) in keep_checks { if !has_next || last.is_none() || !check_fun(sn, last.unwrap()) { - if *counter > 0 { - *counter -= 1; + if *counter != 0 { keep = true; reason.push(reason1); + if *counter > 0 { + *counter -= 1; + } } if sn.time + Duration::from_std(*within).unwrap() > latest_time { keep = true;