]> git.sesse.net Git - pr0n/commitdiff
Make pr0n-upload.pl output a list of failed files at the end, so it's easier to do...
authorSteinar H. Gunderson <sesse@debian.org>
Sun, 3 Apr 2011 07:46:49 +0000 (09:46 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sun, 3 Apr 2011 07:46:49 +0000 (09:46 +0200)
perl/pr0n-upload.pl

index 95ac0471476eda5446cf52c46926b1318a866fe5..6057ad95abccd1adc472aaf6fa829deff92170d4 100755 (executable)
@@ -18,6 +18,8 @@ use Thread::Queue;
 my $threads = 16;
 my $running_threads :shared = 0;
 my $queue :shared = Thread::Queue->new;
+my @succeeded :shared = ();
+my @failed :shared = ();
 
 # Enqueue all the images.
 my $url = shift @ARGV;
@@ -40,13 +42,22 @@ for my $thread (@threads) {
        $thread->join();
 }
 
+if (scalar @failed != 0 && scalar @succeeded != 0) {
+       # Output failed files in an easily-pastable format.
+       print "\nFailed files: ", join(' ', @failed), "\n";
+}
+
 sub upload_thread {
        $running_threads++;
 
        my $dav = init_dav($url, $user, $pass);
        while (my $filename = $queue->dequeue_nb) {
-               $dav->put(-local => $filename, -url => $url)
-                       or warn "Couldn't upload $filename: " . $dav->message . "\n";
+               if ($dav->put(-local => $filename, -url => $url)) {
+                       push @succeeded, $filename;
+               } else {
+                       push @failed, $filename;
+                       warn "Couldn't upload $filename: " . $dav->message . "\n";
+               }
        }
        
        $running_threads--;