Navigation Menu

Skip to content

Commit

Permalink
Added an --outputurls command line option.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 6, 2009
1 parent 6e344a0 commit f040b90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cleanup_offload_cache.pl
Expand Up @@ -53,14 +53,16 @@ sub loadMetadata {
}

sub usage {
die("USAGE: $0 <offloaddir> [--nukeshortfiles] [--youngerthan=X]\n")
die("USAGE: $0 <offloaddir> [--outputurls] [--nukeshortfiles] [--youngerthan=X]\n")
}

my $youngerthan = undef;
my $nukeshortfiles = 0;
my $outputurls = 0;
my $offloaddir = undef;
foreach (@ARGV) {
$nukeshortfiles = 1, next if ($_ eq '--nukeshortfiles');
$outputurls = 1, next if ($_ eq '--outputurls');
$youngerthan = $1, next if (/\A--youngerthan=(\d+)\Z/);
$offloaddir = $_, next if not defined $offloaddir;
usage();
Expand Down Expand Up @@ -144,11 +146,17 @@ sub usage {
next;
}

$headrequests++;
my $len = $metadata{'Content-Length'};
my $hostname = $metadata{'X-Offload-Hostname'};
my $origurl = $metadata{'X-Offload-Orig-URL'};
my $url = 'http://' . $hostname . $origurl;

if ($outputurls) {
print "$url\n";
next;
}

$headrequests++;
my $request = HTTP::Request->new(HEAD => $url);
my $response = $ua->request($request);

Expand Down Expand Up @@ -186,8 +194,11 @@ sub usage {

closedir(DIRH);

print("Recovered $diskrecovered bytes of $totalfilespace.\n");
print("$filesseen files seen, $filesdelete deleted.\n");
print("$headrequests HTTP HEAD requests.\n");
if (not $outputurls) {
print("Recovered $diskrecovered bytes of $totalfilespace.\n");
print("$filesseen files seen, $filesdelete deleted.\n");
print("$headrequests HTTP HEAD requests.\n");
}

exit 0;

0 comments on commit f040b90

Please sign in to comment.