Package: apt-file
Version: 2.4.2
Tags: patch

diffindex-download calls url_not_found when looking for the index file and 
when downloading the Contents file, resulting in double requests.

You could just pass --fail to curl and look for the exit code 22.
The attached patch does that. It is a bit ugly, though.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net
--- unpacked/usr/bin/diffindex-download	2011-07-24 11:10:00.000000000 -0500
+++ /usr/bin/diffindex-download	2012-03-10 19:36:43.000000000 -0600
@@ -112,13 +112,12 @@
 
     my $index_url = "$baseurl.diff/Index";
     info("Downloading Index $index_url:\n");
-    if (url_not_found($index_url)) {
-        die "No Index available.\n";
-    }
     {
         # don't make curl print the progress bar for the index
         my $verbose;
-        download( $index_url, $newindexfile, $oldindexfile );
+        if (!download( $index_url, $newindexfile, $oldindexfile )) {
+	    die "No Index available.\n";
+	}
     }
     if ( ! -e $newindexfile ) {
         info("Index is up-to-date.\n");
@@ -212,21 +211,20 @@
         $command .= " " . quotemeta($url) . " -o " . quotemeta( $urls{$url} );
     }
 
-    system_or_die( $command,
+    my $es = system_or_die( $command,
         "Download of " . join( " ", keys %urls ) . " failed",
         [ values %urls ]
     );
+    return ($es ne 22);
 }
 
 sub download_full {
 
-    if ( url_not_found($url) ) {
+    info("Downloading complete file $url\n");
+    if (!download( $url, "${target}_new", $target )) {
         info("Ignoring source without Contents File:\n  $url\n");
         return;
     }
-
-    info("Downloading complete file $url\n");
-    download( $url, "${target}_new", $target );
     if (! -e "${target}_new") {
         info("File is up-to-date.\n");
         exit(0);
@@ -246,24 +244,6 @@
     unlink $oldindexfile if -e $oldindexfile;
 }
 
-sub url_not_found {
-    my $url = shift;
-
-    my $cmd     = "curl -L -s -I -g $curl_opts" . quotemeta($url);
-    my $headers = qx{$cmd};
-    debug("'$cmd' ($?):\n$headers");
-
-    if ( WIFEXITED($?) && WEXITSTATUS($?) == 19 ) {
-
-        # FTP file not found
-        return 1;
-    }
-    if ( $headers =~ m{^HTTP/1.. 404}m ) {
-        return 1;
-    }
-    return 0;
-}
-
 sub parse_index {
     my $file = shift;
 
@@ -336,6 +316,7 @@
     system($command);
     if ( WIFEXITED($?) ) {
         if ( WEXITSTATUS($?) != 0 ) {
+	    return 22 if (WEXITSTATUS($?) eq 22 && $command =~ m/^curl/);
             warn "$msg\n" if $msg;
             cleanup($cleanup);
             die "Command exited with code " . WEXITSTATUS($?) . "\n";

Reply via email to