summaryrefslogtreecommitdiffstats
path: root/files/reprepro/snapshots
diff options
context:
space:
mode:
authorCyril Brulebois <cyril@debamax.com>2016-04-05 14:48:59 +0200
committerCyril Brulebois <cyril@debamax.com>2016-04-05 14:50:04 +0200
commit464e257aa30d90fc2167013967c2eafd78d4d9df (patch)
tree6d61627cbb82b09c86c0c30d91564ae9a6ae0641 /files/reprepro/snapshots
parent5b801c1436a0b028c0f59ed5d2e1450d24a01765 (diff)
Introduce verbose_print to respect VERBOSE env var.
Default to being less verbose by default, while still making it possible to access debug information. Signed-off-by: Cyril Brulebois <cyril@debamax.com>
Diffstat (limited to 'files/reprepro/snapshots')
-rwxr-xr-xfiles/reprepro/snapshots/time_based/tails-delete-expired-apt-snapshots25
1 files changed, 15 insertions, 10 deletions
diff --git a/files/reprepro/snapshots/time_based/tails-delete-expired-apt-snapshots b/files/reprepro/snapshots/time_based/tails-delete-expired-apt-snapshots
index 862e0d1..4cbb349 100755
--- a/files/reprepro/snapshots/time_based/tails-delete-expired-apt-snapshots
+++ b/files/reprepro/snapshots/time_based/tails-delete-expired-apt-snapshots
@@ -17,6 +17,11 @@ sub usage {
die "Usage: $0 [--dry-run] archive-directory";
}
+sub verbose_print {
+ print @_
+ if $ENV{VERBOSE};
+}
+
my $dryrun = 0;
GetOptions ("dry-run" => \$dryrun)
or usage();
@@ -39,7 +44,7 @@ my @snapshots_dirs = File::Find::Rule->directory()
->name( 'snapshots' )
->in( "$archive_dir/dists" );
-print "found snapshots directories: @snapshots_dirs\n";
+verbose_print("found snapshots directories: @snapshots_dirs\n");
# Let's load once and for all references known by reprepro to see
# which suites/snapshots are present there to see what needs removing:
@@ -48,7 +53,7 @@ my @reprepro_references =
map { (split / /, $_)[0] }
grep { $_ =~ /^s=/ }
capture("reprepro -b $archive_dir dumpreferences");
-print "reprepro-known snapshot references:", (join "\n - ", '', @reprepro_references), "\n";
+verbose_print("reprepro-known snapshot references:", (join "\n - ", '', @reprepro_references), "\n");
my $now = DateTime->now();
my $removed = 0;
@@ -61,7 +66,7 @@ foreach my $dir (@snapshots_dirs) {
$suite =~ s{ $archive_dir/dists/ }{}x;
$suite =~ s{/snapshots}{};
- print "Looking at snapshots for $suite under $dir\n";
+ verbose_print("Looking at snapshots for $suite under $dir\n");
foreach my $snapshot (glob("$dir/*")) {
my $timestamp = basename $snapshot;
# Get Valid-Until:
@@ -79,20 +84,20 @@ foreach my $dir (@snapshots_dirs) {
# Work around UTC suffix, which isn't parsed by DateTime::Format::Mail:
$valid_until =~ s/UTC$/+0000/;
- print " - $snapshot is valid until $valid_until\n";
+ verbose_print(" - $snapshot is valid until $valid_until\n");
my $date = DateTime::Format::Mail->parse_datetime($valid_until);
if (DateTime->compare($now, $date) > 0) {
- print " -> expiration time reached\n";
+ verbose_print(" -> expiration time reached\n");
# Let's look at the references in reprepro to see if there's
# something to delete:
my $db_id = "s=$suite=$timestamp";
if (grep { $db_id eq $_ } @reprepro_references) {
- print " $db_id found in the db, forgetting\n";
+ verbose_print(" $db_id found in the db, forgetting\n");
run("reprepro -b $archive_dir _removereferences $db_id")
if ! $dryrun;
$removed++;
- print " done\n";
+ verbose_print(" done\n");
}
# Let's remove the snapshot entirely:
@@ -100,14 +105,14 @@ foreach my $dir (@snapshots_dirs) {
if ! $dryrun;
}
else {
- print " -> nothing to do\n";
+ verbose_print(" -> nothing to do\n");
}
}
}
if ($removed > 0) {
- print "at least one snapshot was removed, calling reprepro deleteunreferenced\n";
+ verbose_print("at least one snapshot was removed, calling reprepro deleteunreferenced\n");
run("reprepro -b $archive_dir deleteunreferenced")
if ! $dryrun;
- print "done\n";
+ verbose_print("done\n");
}