Check for failure when running wget
[ghc-hetmet.git] / darcs-all
index 56290ab..a80e6f8 100644 (file)
--- a/darcs-all
+++ b/darcs-all
@@ -112,6 +112,20 @@ sub warning {
     }
 }
 
+sub download {
+    my ($from, $to) = @_;
+
+    my @cmd = ("wget", $from, "-O", $to);
+    message "== running @cmd";
+    system @cmd;
+    if ($? == -1) {
+        die "Failed to execute wget: $!\n";
+    }
+    elsif ($? != 0) {
+        die "wget failed: $?\n";
+    }
+}
+
 sub darcs {
     message "== running darcs @_";
     system ("darcs", @_) == 0
@@ -132,7 +146,7 @@ sub darcsall {
     @repos = <IN>;
     close IN;
 
-    REPO: foreach (@repos) {
+    foreach (@repos) {
         chomp;
         if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
             $localpath = $1;
@@ -164,6 +178,10 @@ sub darcsall {
             die "Bad line: $_";
         }
     }
+
+    if ($_[0] eq "pull" || $_[0] eq "pul") {
+        &sync_tarballs();
+    }
 }
 
 sub darcsget {
@@ -215,6 +233,63 @@ sub darcsget {
             die "Bad line: $_";
         }
     }
+
+    &sync_tarballs();
+}
+
+sub sync_tarballs {
+    my $localpath;
+    my $localdirectory;
+    my $localfilename;
+    my $actualpath;
+    my $actualfilename;
+    my $remotepath;
+    my $path;
+    my @tarballs;
+    my %localtarballs;
+    my ($repo_base, $checked_out_tree) = getrepo();
+
+    message "== Syncing tarballs";
+
+    open IN, "< tarballs" or die "Can't open packages file";
+    @tarballs = <IN>;
+    close IN;
+
+    foreach (@tarballs) {
+        chomp;
+        if (m@^([^# ]+)/([^#/ ]+) +([^ ]+)$@) {
+            $localdirectory = $1;
+            $localfilename = $2;
+            $remotepath = $3;
+            $localpath = "$localdirectory/$localfilename";
+
+            $localtarballs{$localdirectory}{$localfilename} = 1;
+
+            if (! -e $localpath) {
+                if ($checked_out_tree) {
+                    $path = "$repo_base/$localpath";
+                }
+                else {
+                    $path = "$repo_base/$remotepath";
+                }
+                &download($path, $localpath);
+            }
+        }
+        elsif (! /^(#.*)?$/) {
+            die "Bad line: $_";
+        }
+    }
+
+    foreach $localdirectory (keys %localtarballs) {
+        FILE: foreach $actualpath (glob "$localdirectory/*.tar.gz $localdirectory/*.tar.bz2") {
+            $actualfilename = $actualpath;
+            $actualfilename =~ s#.*/##;
+            if (! defined($localtarballs{$localdirectory}{$actualfilename})) {
+                message "== Deleting $actualpath";
+                unlink $actualpath;
+            }
+        }
+    }
 }
 
 sub main {
@@ -279,5 +354,23 @@ sub main {
     }
 }
 
+END {
+    message "== Checking for old bytestring repo";
+    if (-d "libraries/bytestring/_darcs") {
+        if ((system "darcs annotate --repodir libraries/bytestring --match 'hash 20080118173113-3fd76-d5b74c04372a297b585ebea4e16d524551ce5035' > /dev/null 2> /dev/null") == 0) {
+            print <<EOF;
+============================
+ATTENTION!
+
+You have an old bytestring repository in your GHC tree!
+
+Please remove it (e.g. "rm -r libraries/bytestring"), and the new
+version of bytestring will be used from a tarball instead.
+============================
+EOF
+        }
+    }
+}
+
 main(@ARGV);