Added an --outputurls command line option.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 06 Nov 2009 11:12:05 -0800
changeset 135 36e73dbcadf3
parent 134 dc073c76a283
child 136 d914c6063504
Added an --outputurls command line option.
cleanup_offload_cache.pl
--- a/cleanup_offload_cache.pl	Sun May 31 15:02:22 2009 -0500
+++ b/cleanup_offload_cache.pl	Fri Nov 06 11:12:05 2009 -0800
@@ -53,14 +53,16 @@
 }
 
 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();
@@ -144,11 +146,17 @@
         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);
 
@@ -186,8 +194,11 @@
 
 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;