* Refactoring.

This commit is contained in:
Eelco Dolstra 2007-03-26 20:49:22 +00:00
parent f3584ff535
commit 7edd2e2cd2

View file

@ -14,7 +14,7 @@ EOF
# Get the target host. # Get the target host.
my $sshHost = shift @ARGV; my $sshHost;
my @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or ""); my @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or "");
my $sign = 0; my $sign = 0;
@ -22,38 +22,54 @@ my $sign = 0;
my $compressor = "cat"; my $compressor = "cat";
my $decompressor = "cat"; my $decompressor = "cat";
my $toMode = 1;
# !!! Copied from nix-pack-closure, should put this in a module. # !!! Copied from nix-pack-closure, should put this in a module.
my %storePathsSeen;
my @storePaths = (); my @storePaths = ();
while (@ARGV) { while (@ARGV) {
my $storePath = shift @ARGV; my $arg = shift @ARGV;
if ($storePath eq "--sign") { if ($arg eq "--sign") {
$sign = 1; $sign = 1;
next; next;
} }
if ($storePath eq "--gzip") { if ($arg eq "--gzip") {
$compressor = "gzip"; $compressor = "gzip";
$decompressor = "gunzip"; $decompressor = "gunzip";
next; next;
} }
# $storePath might be a symlink to the store, so resolve it. if (!defined $sshHost) {
$storePath = (`$binDir/nix-store --query --resolve '$storePath'` $sshHost = $arg;
next;
}
push @storePaths, $arg;
}
if ($toMode) { # Copy TO the remote machine.
my @allStorePaths;
my %storePathsSeen;
foreach my $storePath (@storePaths) {
# $arg might be a symlink to the store, so resolve it.
my $storePath2 = (`$binDir/nix-store --query --resolve '$storePath'`
or die "cannot resolve `$storePath'"); or die "cannot resolve `$storePath'");
chomp $storePath; chomp $storePath2;
# Get the closure of this path. # Get the closure of this path.
my $pid = open(READ, my $pid = open(READ,
"$binDir/nix-store --query --requisites '$storePath'|") or die; "$binDir/nix-store --query --requisites '$storePath2'|") or die;
while (<READ>) { while (<READ>) {
chomp; chomp;
die "bad: $_" unless /^\//; die "bad: $_" unless /^\//;
if (!defined $storePathsSeen{$_}) { if (!defined $storePathsSeen{$_}) {
push @storePaths, $_; push @allStorePaths, $_;
$storePathsSeen{$_} = 1; $storePathsSeen{$_} = 1
} }
} }
@ -62,7 +78,7 @@ while (@ARGV) {
# Ask the remote host which paths are invalid. # Ask the remote host which paths are invalid.
open(READ, "ssh @sshOpts $sshHost nix-store --check-validity --print-invalid @storePaths|"); open(READ, "ssh @sshOpts $sshHost nix-store --check-validity --print-invalid @allStorePaths|");
my @missing = (); my @missing = ();
while (<READ>) { while (<READ>) {
chomp; chomp;
@ -79,3 +95,5 @@ if (scalar @missing > 0) {
system("nix-store --export $extraOpts @missing | $compressor | ssh @sshOpts $sshHost '$decompressor | nix-store --import'") == 0 system("nix-store --export $extraOpts @missing | $compressor | ssh @sshOpts $sshHost '$decompressor | nix-store --import'") == 0
or die "copying store paths to remote machine failed: $?"; or die "copying store paths to remote machine failed: $?";
} }
}