forked from lix-project/lix
* Fix the copy-from-other-stores substituter.
This commit is contained in:
parent
ef337f7089
commit
c778ed1768
|
@ -17,25 +17,19 @@ foreach my $dir (@remoteStoresAll) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$ENV{"NIX_REMOTE"} = "";
|
||||||
|
|
||||||
|
|
||||||
sub findStorePath {
|
sub findStorePath {
|
||||||
my $storePath = shift;
|
my $storePath = shift;
|
||||||
|
|
||||||
my $storePathName = basename $storePath;
|
|
||||||
|
|
||||||
foreach my $store (@remoteStores) {
|
foreach my $store (@remoteStores) {
|
||||||
# Determine whether $storePath exists by looking for the
|
my $sourcePath = "$store/store/" . basename $storePath;
|
||||||
# existence of the info file, and if so, get store path info
|
next unless -e $sourcePath || -l $sourcePath;
|
||||||
# from that file. This rather breaks abstraction: we should
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
||||||
# be using `nix-store' for that. But right now there is no
|
return ($store, $sourcePath) if
|
||||||
# good way to tell nix-store to access a store mounted under a
|
system("@bindir@/nix-store --check-validity $storePath") == 0;
|
||||||
# different location (there's $NIX_STORE, but that only works
|
|
||||||
# if the remote store is mounted under its "real" location).
|
|
||||||
my $infoFile = "$store/var/nix/db/info/$storePathName";
|
|
||||||
my $storePath2 = "$store/store/$storePathName";
|
|
||||||
if (-f $infoFile && -e $storePath2) {
|
|
||||||
return ($infoFile, $storePath2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,32 +40,28 @@ if ($ARGV[0] eq "--query") {
|
||||||
|
|
||||||
if ($cmd eq "have") {
|
if ($cmd eq "have") {
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
my $storePath = <STDIN>; chomp $storePath;
|
||||||
(my $infoFile) = findStorePath $storePath;
|
print STDOUT (defined findStorePath($storePath) ? "1\n" : "0\n");
|
||||||
print STDOUT ($infoFile ? "1\n" : "0\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($cmd eq "info") {
|
elsif ($cmd eq "info") {
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
my $storePath = <STDIN>; chomp $storePath;
|
||||||
(my $infoFile) = findStorePath $storePath;
|
my ($store, $sourcePath) = findStorePath($storePath);
|
||||||
if (!$infoFile) {
|
if (!defined $store) {
|
||||||
print "0\n";
|
print "0\n";
|
||||||
next; # not an error
|
next; # not an error
|
||||||
}
|
}
|
||||||
print "1\n";
|
print "1\n";
|
||||||
|
|
||||||
my $deriver = "";
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
||||||
my @references = ();
|
|
||||||
|
|
||||||
open INFO, "<$infoFile" or die "cannot read info file $infoFile\n";
|
my $deriver = `@bindir@/nix-store --query --deriver $storePath`;
|
||||||
while (<INFO>) {
|
die "cannot query deriver of `$storePath'" if $? != 0;
|
||||||
chomp;
|
chomp $deriver;
|
||||||
/^([\w-]+): (.*)$/ or die "bad info file";
|
$deriver = "" if $deriver eq "unknown-deriver";
|
||||||
my $key = $1;
|
|
||||||
my $value = $2;
|
my @references = split "\n",
|
||||||
if ($key eq "Deriver") { $deriver = $value; }
|
`@bindir@/nix-store --query --references $storePath`;
|
||||||
elsif ($key eq "References") { @references = split ' ', $value; }
|
die "cannot query references of `$storePath'" if $? != 0;
|
||||||
}
|
|
||||||
close INFO;
|
|
||||||
|
|
||||||
print "$deriver\n";
|
print "$deriver\n";
|
||||||
print scalar @references, "\n";
|
print scalar @references, "\n";
|
||||||
|
@ -87,8 +77,8 @@ if ($ARGV[0] eq "--query") {
|
||||||
elsif ($ARGV[0] eq "--substitute") {
|
elsif ($ARGV[0] eq "--substitute") {
|
||||||
die unless scalar @ARGV == 2;
|
die unless scalar @ARGV == 2;
|
||||||
my $storePath = $ARGV[1];
|
my $storePath = $ARGV[1];
|
||||||
(my $infoFile, my $sourcePath) = findStorePath $storePath;
|
my ($store, $sourcePath) = findStorePath $storePath;
|
||||||
die unless $infoFile;
|
die unless $store;
|
||||||
print "\n*** Copying `$storePath' from `$sourcePath'\n\n";
|
print "\n*** Copying `$storePath' from `$sourcePath'\n\n";
|
||||||
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
|
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
|
||||||
or die "cannot copy `$sourcePath' to `$storePath'";
|
or die "cannot copy `$sourcePath' to `$storePath'";
|
||||||
|
|
Loading…
Reference in a new issue