forked from lix-project/lix
Binary caches: use a better key
Use the hash part of the store path as a key rather than a hash of the store path. This is enough to get the desired privacy property.
This commit is contained in:
parent
6b1e671ac6
commit
6ec7460af1
|
@ -1,6 +1,7 @@
|
||||||
#! @perl@ -w @perlFlags@
|
#! @perl@ -w @perlFlags@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use File::Basename;
|
||||||
use Nix::Config;
|
use Nix::Config;
|
||||||
use Nix::Store;
|
use Nix::Store;
|
||||||
|
|
||||||
|
@ -12,9 +13,11 @@ sub getInfoFrom {
|
||||||
my ($storePath, $pathHash, $binaryCacheUrl) = @_;
|
my ($storePath, $pathHash, $binaryCacheUrl) = @_;
|
||||||
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo";
|
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo";
|
||||||
#print STDERR "checking $infoUrl...\n";
|
#print STDERR "checking $infoUrl...\n";
|
||||||
my $s = `$Nix::Config::curl --fail --silent --location ${infoUrl}`;
|
my $s = `$Nix::Config::curl --fail --silent --location $infoUrl`;
|
||||||
if ($? != 0) {
|
if ($? != 0) {
|
||||||
#print STDERR "GOT CURL REPLY ", $? >> 8, "\n";
|
my $status = $? >> 8;
|
||||||
|
print STDERR "could not download ‘$infoUrl’ (curl returned status ", $? >> 8, ")\n"
|
||||||
|
if $status != 22 && $status != 37;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
my ($storePath2, $url, $compression, $fileHash, $fileSize, $narHash, $narSize, $deriver);
|
my ($storePath2, $url, $compression, $fileHash, $fileSize, $narHash, $narSize, $deriver);
|
||||||
|
@ -51,7 +54,7 @@ sub getInfoFrom {
|
||||||
sub getInfo {
|
sub getInfo {
|
||||||
my ($storePath) = @_;
|
my ($storePath) = @_;
|
||||||
|
|
||||||
my $pathHash = hashString("sha256", 1, $storePath);
|
my $pathHash = substr(basename($storePath), 0, 32);
|
||||||
|
|
||||||
cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
|
cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
|
||||||
my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl);
|
my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl);
|
||||||
|
@ -65,7 +68,7 @@ sub getInfo {
|
||||||
sub downloadBinary {
|
sub downloadBinary {
|
||||||
my ($storePath) = @_;
|
my ($storePath) = @_;
|
||||||
|
|
||||||
my $pathHash = hashString("sha256", 1, $storePath);
|
my $pathHash = substr(basename($storePath), 0, 32);
|
||||||
|
|
||||||
cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
|
cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
|
||||||
my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl);
|
my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl);
|
||||||
|
@ -124,7 +127,9 @@ if ($ARGV[0] eq "--query") {
|
||||||
|
|
||||||
elsif ($ARGV[0] eq "--substitute") {
|
elsif ($ARGV[0] eq "--substitute") {
|
||||||
my $storePath = $ARGV[1] or die;
|
my $storePath = $ARGV[1] or die;
|
||||||
exit 1 unless downloadBinary($storePath);
|
if (!downloadBinary($storePath)) {
|
||||||
|
print STDERR "could not download ‘$storePath’ from any binary cache\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -218,12 +218,12 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $infoName = hashString("sha256", 1, $storePath);
|
my $pathHash = substr(basename($storePath), 0, 32);
|
||||||
|
|
||||||
if ($localCopy) {
|
if ($localCopy) {
|
||||||
my $dst = "$localArchivesDir/$infoName.narinfo";
|
my $dst = "$localArchivesDir/$pathHash.narinfo";
|
||||||
if ($force || ! -f $dst) {
|
if ($force || ! -f $dst) {
|
||||||
my $tmp = "$localArchivesDir/.tmp.$$.$infoName";
|
my $tmp = "$localArchivesDir/.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;
|
||||||
|
|
Loading…
Reference in a new issue