Created
April 3, 2017 14:35
-
-
Save foursixnine/623397e6f3231c3dc8a0c435d874e5df to your computer and use it in GitHub Desktop.
Enforce caching cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use File::Basename; | |
use Fcntl qw(:flock); | |
use List::MoreUtils; | |
use Data::Dumper; | |
use JSON; | |
use File::Glob; | |
my $cache = {}; | |
my $host = "http://openqa.suse.de"; | |
#my $limit = 5; | |
my $delete = 0; | |
my $db_file = "/var/lib/openqa/cache/cache.db"; | |
sub read_db { | |
local $/; # use slurp mode to read the whole file at once. | |
open(my $fh, "<", $db_file) or die "File not found"; | |
flock($fh, LOCK_EX); | |
eval { $cache = JSON->new->relaxed->decode(<$fh>); }; | |
die "parse error in $db_file:\n$@" if $@; | |
print("Got: \n"); | |
print(Dumper($cache)); | |
close($fh); | |
print("Read db file\n"); | |
} | |
read_db; | |
my @assets = glob("/var/lib/openqa/cache/*.img /var/lib/openqa/cache/*.qcow2 /var/lib/openqa/cache/*.iso"); | |
foreach my $asset (@assets){ | |
if( -B $asset){ | |
if ( grep /$asset/, @{$cache->{$host}}){ | |
print "Keeping $asset\n"; | |
} else { | |
print "Deleting $asset\n"; | |
unlink($asset) or die "Could not delete $asset\n"; | |
} | |
} else { | |
print "Found $asset but is not the files we're looking for\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://progress.opensuse.org/issues/17574