* Don't access /nix/var/nix/db directly but use the Nix Perl bindings.

This commit is contained in:
Eelco Dolstra 2010-03-04 13:25:12 +00:00
parent ceeba31320
commit 00b2f7c141

View file

@ -4,6 +4,7 @@ use strict;
use Exporter; use Exporter;
use File::Path; use File::Path;
use File::Basename; use File::Basename;
use Nix;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
@ -17,42 +18,16 @@ our @EXPORT = qw(
sub isValidPath { sub isValidPath {
my $path = shift; my $path = shift;
#$SIG{CHLD} = 'DEFAULT'; # !!! work around system() failing if SIGCHLD is ignored return Nix::isValidPath($path);
#return system("nix-store --check-validity $path 2> /dev/null") == 0;
# This is faster than calling nix-store, but it breaks abstraction...
return -e ("/nix/var/nix/db/info/" . basename $path);
} }
sub queryPathInfo { sub queryPathInfo {
my $path = shift; my $path = shift;
# !!! like above, this breaks abstraction. What we really need is my $hash = Nix::queryPathHash($path);
# Perl bindings for libstore :-) my $deriver = Nix::queryDeriver($path);
my @refs = Nix::queryReferences($path);
open FH, "</nix/var/nix/db/info/" . basename $path
or die "cannot open info file for $path";
my $hash;
my $deriver;
my @refs = ();
while (<FH>) {
if (/^Hash: (\S+)$/) {
$hash = $1;
}
elsif (/^Deriver: (\S+)$/) {
$deriver = $1;
}
elsif (/^References: (.*)$/) {
@refs = split / /, $1;
}
}
close FH;
die "path $path does not have a hash" unless defined $hash;
return ($hash, $deriver, \@refs); return ($hash, $deriver, \@refs);
} }