* (Unnecessary) refactoring.

This commit is contained in:
Eelco Dolstra 2005-02-24 14:06:18 +00:00
parent bfaf83a0fd
commit 95e870a113

View file

@ -30,9 +30,9 @@ my $localCopy;
my $localArchivesDir; my $localArchivesDir;
my $localManifestFile; my $localManifestFile;
my $archives_put_url; my $archivesPutURL;
my $archives_get_url; my $archivesGetURL;
my $manifest_put_url; my $manifestPutURL;
if ($ARGV[0] eq "--copy") { if ($ARGV[0] eq "--copy") {
die "syntax: nix-push --copy ARCHIVES_DIR MANIFEST_FILE PATHS...\n" if scalar @ARGV < 3; die "syntax: nix-push --copy ARCHIVES_DIR MANIFEST_FILE PATHS...\n" if scalar @ARGV < 3;
@ -45,9 +45,9 @@ else {
die "syntax: nix-push ARCHIVES_PUT_URL ARCHIVES_GET_URL " . die "syntax: nix-push ARCHIVES_PUT_URL ARCHIVES_GET_URL " .
"MANIFEST_PUT_URL PATHS...\n" if scalar @ARGV < 3; "MANIFEST_PUT_URL PATHS...\n" if scalar @ARGV < 3;
$localCopy = 0; $localCopy = 0;
$archives_put_url = shift @ARGV; $archivesPutURL = shift @ARGV;
$archives_get_url = shift @ARGV; $archivesGetURL = shift @ARGV;
$manifest_put_url = shift @ARGV; $manifestPutURL = shift @ARGV;
} }
@ -100,13 +100,13 @@ close NIX;
# Instantiate store expressions from the Nix expression. # Instantiate store expressions from the Nix expression.
my @storeexprs; my @storeExprs;
print STDERR "instantiating store expressions...\n"; print STDERR "instantiating store expressions...\n";
open STOREEXPRS, "$binDir/nix-instantiate $nixfile |" or die "cannot run nix-instantiate"; open STOREEXPRS, "$binDir/nix-instantiate $nixfile |" or die "cannot run nix-instantiate";
while (<STOREEXPRS>) { while (<STOREEXPRS>) {
chomp; chomp;
die unless /^\//; die unless /^\//;
push @storeexprs, $_; push @storeExprs, $_;
} }
close STOREEXPRS; close STOREEXPRS;
@ -114,9 +114,9 @@ close STOREEXPRS;
# Realise the store expressions. # Realise the store expressions.
print STDERR "creating archives...\n"; print STDERR "creating archives...\n";
my @narpaths; my @narPaths;
my @tmp = @storeexprs; my @tmp = @storeExprs;
while (scalar @tmp > 0) { while (scalar @tmp > 0) {
my $n = scalar @tmp; my $n = scalar @tmp;
if ($n > 256) { $n = 256 }; if ($n > 256) { $n = 256 };
@ -127,7 +127,7 @@ while (scalar @tmp > 0) {
while (<NARPATHS>) { while (<NARPATHS>) {
chomp; chomp;
die unless (/^\//); die unless (/^\//);
push @narpaths, "$_"; push @narPaths, "$_";
} }
close NARPATHS; close NARPATHS;
} }
@ -139,10 +139,10 @@ print STDERR "creating manifest...\n";
my %narFiles; my %narFiles;
my %patches; my %patches;
my @nararchives; my @narArchives;
for (my $n = 0; $n < scalar @storePaths; $n++) { for (my $n = 0; $n < scalar @storePaths; $n++) {
my $storePath = $storePaths[$n]; my $storePath = $storePaths[$n];
my $nardir = $narpaths[$n]; my $narDir = $narPaths[$n];
$storePath =~ /\/([^\/]*)$/; $storePath =~ /\/([^\/]*)$/;
my $basename = $1; my $basename = $1;
@ -150,23 +150,23 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
my $narname = "$basename.nar.bz2"; my $narname = "$basename.nar.bz2";
my $narfile = "$nardir/$narname"; my $narFile = "$narDir/$narname";
(-f $narfile) or die "narfile for $storePath not found"; (-f $narFile) or die "narfile for $storePath not found";
push @nararchives, $narfile; push @narArchives, $narFile;
open SHA1, "$nardir/narbz2-hash" or die "cannot open narbz2-hash"; open SHA1, "$narDir/narbz2-hash" or die "cannot open narbz2-hash";
my $narbz2Hash = <SHA1>; my $narbz2Hash = <SHA1>;
chomp $narbz2Hash; chomp $narbz2Hash;
$narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash"; $narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
close SHA1; close SHA1;
open SHA1, "$nardir/nar-hash" or die "cannot open nar-hash"; open SHA1, "$narDir/nar-hash" or die "cannot open nar-hash";
my $narHash = <SHA1>; my $narHash = <SHA1>;
chomp $narHash; chomp $narHash;
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash"; $narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
close SHA1; close SHA1;
my $narbz2Size = (stat $narfile)[7]; my $narbz2Size = (stat $narFile)[7];
my $references = `$binDir/nix-store --query --references '$storePath'`; my $references = `$binDir/nix-store --query --references '$storePath'`;
die "cannot query references for `$storePath'" if $? != 0; die "cannot query references for `$storePath'" if $? != 0;
@ -181,7 +181,7 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
if ($localCopy) { if ($localCopy) {
$url = "file://$localArchivesDir/$narname"; $url = "file://$localArchivesDir/$narname";
} else { } else {
$url = "$archives_get_url/$narname"; $url = "$archivesGetURL/$narname";
} }
$narFiles{$storePath} = [ $narFiles{$storePath} = [
{ url => $url { url => $url
@ -208,23 +208,30 @@ sub copyFile {
# Upload the archives. # Upload the archives.
print STDERR "uploading archives...\n"; print STDERR "uploading archives...\n";
foreach my $nararchive (@nararchives) {
$nararchive =~ /\/([^\/]*)$/; sub archiveExists {
my $name = shift;
print STDERR " HEAD on $archivesGetURL/$name\n";
return system("$curl --head $archivesGetURL/$name > /dev/null") == 0;
}
foreach my $narArchive (@narArchives) {
$narArchive =~ /\/([^\/]*)$/;
my $basename = $1; my $basename = $1;
if ($localCopy) { if ($localCopy) {
if (! -f "$localArchivesDir/$basename") { if (! -f "$localArchivesDir/$basename") {
print STDERR " $nararchive\n"; print STDERR " $narArchive\n";
copyFile $nararchive, "$localArchivesDir/$basename"; copyFile $narArchive, "$localArchivesDir/$basename";
} }
} }
else { else {
if (system("$curl --head $archives_get_url/$basename > /dev/null") != 0) { if (!archiveExists("$basename")) {
print STDERR " $nararchive\n"; print STDERR " $narArchive\n";
system("$curl --show-error --upload-file " . system("$curl --show-error --upload-file " .
"'$nararchive' '$archives_put_url/$basename' > /dev/null") == 0 or "'$narArchive' '$archivesPutURL/$basename' > /dev/null") == 0 or
die "curl failed on $nararchive: $?"; die "curl failed on $narArchive: $?";
} }
} }
} }
@ -236,6 +243,6 @@ if ($localCopy) {
copyFile $manifest, $localManifestFile; copyFile $manifest, $localManifestFile;
} else { } else {
system("$curl --show-error --upload-file " . system("$curl --show-error --upload-file " .
"'$manifest' '$manifest_put_url' > /dev/null") == 0 or "'$manifest' '$manifestPutURL' > /dev/null") == 0 or
die "curl failed on $manifest: $?"; die "curl failed on $manifest: $?";
} }