Bug#690024: A similar patch while one line shorter

Regid Ichira regid23 at nt1.in
Tue Oct 9 10:00:45 UTC 2012


  A one line shorter then before, provided the Perl construct

    if (condition) {
        something piped_to |
    }
    else {
        something_else piped_to |
    }
    or die "message"

does what seems to me the obviuos intention.


--- a/usr/bin/rc-alert	2012-09-25 01:45:59.000000000 +0200
+++ n/usr/bin/rc-alert	2012-10-09 01:26:26.000000000 +0200
@@ -158,8 +158,13 @@ $excludedists = remove_duplicate_values(
 
 ## First download the RC bugs page
 
-unless (system("command -v wget >/dev/null 2>&1") == 0) {
-    die "$progname: this program requires the wget package to be installed\n";
+my $curl_or_wget;
+if (system("command -v curl >/dev/null 2>&1") == 0) {
+    $curl_or_wget = "curl";
+} elsif (system("command -v wget >/dev/null 2>&1") == 0) {
+    $curl_or_wget = "wget";
+} else {
+    die "$progname: this program requires either the curl or the wget package to be installed\n";
 }
 
 
@@ -171,16 +176,32 @@ if (! -d $cachedir and $forcecache) {
 if (-d $cachedir) {
     chdir $cachedir or die "$progname: can't cd $cachedir: $!\n";
 
-    # Either use the cached version because the remote hasn't been updated
-    # (-N) or download a complete new copy (--no-continue)
-    if (system('wget', '-qN', '--no-continue', $url) != 0) {
+    # Is
+    #     curl -qsR -C - $url
+    # equivalent to 
+    #     wget -qN --no-continue $url
+    # ?
+    if ("$curl_or_wget" eq "curl") {
+        if (system('curl', '-qsR', '-C', '-', $url) != 0) {
+	    die "$progname: curl failed!\n";
+        }
+    } elsif (system('wget', '-qN', '--no-continue', $url) != 0) {
+        # $curl_or_wget" eq "wget" 
+        # Either use the cached version because the remote hasn't
+        # been updated (-N) or download a complete new copy
+        # (--no-continue)
 	die "$progname: wget failed!\n";
     }
     open BUGS, $cachefile or die "$progname: could not read $cachefile: $!\n";
 }
 else {
-    open BUGS, "wget -q -O - $url |" or
-	die "$progname: could not run wget: $!\n";
+    if ("$curl_or_wget" eq "curl") {
+        open BUGS, "curl -qs $url |"
+    } else {
+        # $curl_or_wget" eq "wget" 
+        open BUGS, "wget -q -O - $url |"
+    }
+    or die "$progname: could not run $curl_or_wget: $!\n";
 }
 
 ## Get list of installed packages (not source packages)
@@ -204,8 +225,13 @@ if ($popcon) {
 	    or die "$progname: Unable to access popcon data: $!";
 	$pc_regex = '(\d+)\s\d+\s(\S+)';
     } else {
-	open POPCON, "wget -q -O - http://popcon.debian.org/by_$pc_by.gz | gunzip -c |"
-	    or die "$progname: Not able to receive remote popcon data!";
+        if ("$curl_or_wget" eq "curl") {
+	    open POPCON, "curl -qs http://popcon.debian.org/by_$pc_by.gz | gunzip -c |"
+        } else {
+            # $curl_or_wget" eq "wget" 
+	    open POPCON, "wget -q -O - http://popcon.debian.org/by_$pc_by.gz | gunzip -c |"
+        }
+        or die "$progname: Not able to receive remote popcon data!";
 	$pc_regex = '(\d+)\s+(\S+)\s+(\d+\s+){5}\(.*\)';
     }
 



More information about the devscripts-devel mailing list