nix-push: Remove the upload feature

This commit is contained in:
Eelco Dolstra 2012-07-26 17:13:38 -04:00
parent 609586a16d
commit e3ce54ccee
1 changed files with 24 additions and 51 deletions

View File

@ -24,22 +24,15 @@ $curl = "$curl $extraCurlFlags" if defined $extraCurlFlags;
# Parse the command line. # Parse the command line.
my $compressionType = "xz"; my $compressionType = "xz";
my $force = 0; my $force = 0;
my $destDir;
my $localCopy;
my $localArchivesDir;
my $archivesPutURL;
my $archivesGetURL;
my @roots; my @roots;
sub showSyntax { sub showSyntax {
print STDERR <<EOF print STDERR <<EOF
Usage: nix-push --copy ARCHIVES_DIR PATHS... Usage: nix-push --dest DIR PATHS...
or: nix-push --upload ARCHIVES_PUT_URL ARCHIVES_GET_URL PATHS...
`nix-push' copies or uploads the closure of PATHS to the given `nix-push' packs the closure of PATHS into a set of NAR archives
destination. stored in DIR.
EOF EOF
; # ` ; # `
exit 1; exit 1;
@ -54,18 +47,11 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
$compressionType = "bzip2"; $compressionType = "bzip2";
} elsif ($arg eq "--force") { } elsif ($arg eq "--force") {
$force = 1; $force = 1;
} elsif ($arg eq "--copy") { } elsif ($arg eq "--dest") {
$n++; $n++;
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV; die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
$localCopy = 1; $destDir = $ARGV[$n];
$localArchivesDir = $ARGV[$n]; mkpath($destDir, 0, 0755);
mkpath($localArchivesDir, 0, 0755);
} elsif ($arg eq "--upload") {
die "$0: `$arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
$localCopy = 0;
$archivesPutURL = $ARGV[$n + 1];
$archivesGetURL = $ARGV[$n + 2];
$n++;
} elsif (substr($arg, 0, 1) eq "-") { } elsif (substr($arg, 0, 1) eq "-") {
showSyntax; showSyntax;
} else { } else {
@ -73,7 +59,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
} }
} }
showSyntax if !defined $localCopy; showSyntax if !defined $destDir;
# From the given store paths, determine the set of requisite store # From the given store paths, determine the set of requisite store
@ -134,8 +120,8 @@ while (<READ>) {
close READ or die "nix-build failed: $?"; close READ or die "nix-build failed: $?";
# Upload the archives and the corresponding info files. # Copy the archives and the corresponding info files.
print STDERR "uploading/copying archives...\n"; print STDERR "copying archives...\n";
my $totalNarSize = 0; my $totalNarSize = 0;
my $totalCompressedSize = 0; my $totalCompressedSize = 0;
@ -183,24 +169,15 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
printf STDERR "%s [%.2f MiB, %.1f%%]\n", $storePath, printf STDERR "%s [%.2f MiB, %.1f%%]\n", $storePath,
$compressedSize / (1024 * 1024), $compressedSize / $narSize * 100; $compressedSize / (1024 * 1024), $compressedSize / $narSize * 100;
# Upload the compressed NAR. # Copy the compressed NAR.
if ($localCopy) { my $dst = "$destDir/$narName";
my $dst = "$localArchivesDir/$narName";
if (! -f $dst) { if (! -f $dst) {
my $tmp = "$localArchivesDir/.tmp.$$.$narName"; my $tmp = "$destDir/.tmp.$$.$narName";
copy($narFile, $tmp) or die "cannot copy $narFile to $tmp: $!\n"; copy($narFile, $tmp) or die "cannot copy $narFile to $tmp: $!\n";
rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n"; rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n";
} }
} else {
die "unimplemented";
#if (!archiveExists("$basename")) {
# system("$curl --show-error --upload-file " .
# "'$narArchive' '$archivesPutURL/$basename' > /dev/null") == 0 or
# die "curl failed on $narArchive: $?";
#}
}
# Upload the info file. # Write the info file.
my $info; my $info;
$info .= "StorePath: $storePath\n"; $info .= "StorePath: $storePath\n";
$info .= "URL: $narName\n"; $info .= "URL: $narName\n";
@ -220,18 +197,14 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
my $pathHash = substr(basename($storePath), 0, 32); my $pathHash = substr(basename($storePath), 0, 32);
if ($localCopy) { $dst = "$destDir/$pathHash.narinfo";
my $dst = "$localArchivesDir/$pathHash.narinfo";
if ($force || ! -f $dst) { if ($force || ! -f $dst) {
my $tmp = "$localArchivesDir/.tmp.$$.$pathHash.narinfo"; my $tmp = "$destDir/.tmp.$$.$pathHash.narinfo";
open INFO, ">$tmp" or die; open INFO, ">$tmp" or die;
print INFO "$info" or die; print INFO "$info" or die;
close INFO or die; close INFO or die;
rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n"; rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n";
} }
} else {
die "unimplemented";
}
} }
printf STDERR "total compressed size %.2f MiB, %.1f%%\n", printf STDERR "total compressed size %.2f MiB, %.1f%%\n",