2011-10-10 18:12:40 +00:00
|
|
|
package Nix::Store;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-05-10 23:03:23 +00:00
|
|
|
use Nix::Config;
|
2011-10-10 18:12:40 +00:00
|
|
|
|
|
|
|
require Exporter;
|
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
|
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
|
|
|
|
2011-11-29 13:01:24 +00:00
|
|
|
our @EXPORT = qw(
|
|
|
|
isValidPath queryReferences queryPathInfo queryDeriver queryPathHash
|
2012-07-17 22:55:39 +00:00
|
|
|
queryPathFromHashPart
|
2014-07-11 14:02:19 +00:00
|
|
|
topoSortPaths computeFSClosure followLinksToStorePath exportPaths importPaths
|
2011-12-02 12:09:24 +00:00
|
|
|
hashPath hashFile hashString
|
|
|
|
addToStore makeFixedOutputPath
|
2012-03-19 03:14:21 +00:00
|
|
|
derivationFromPath
|
2011-11-29 13:01:24 +00:00
|
|
|
);
|
2011-10-10 18:12:40 +00:00
|
|
|
|
|
|
|
our $VERSION = '0.15';
|
|
|
|
|
2012-05-10 23:03:23 +00:00
|
|
|
sub backtick {
|
|
|
|
open(RES, "-|", @_) or die;
|
|
|
|
local $/;
|
|
|
|
my $res = <RES> || "";
|
|
|
|
close RES or die;
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Nix::Config::useBindings) {
|
|
|
|
require XSLoader;
|
|
|
|
XSLoader::load('Nix::Store', $VERSION);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Provide slow fallbacks of some functions on platforms that don't
|
|
|
|
# support the Perl bindings.
|
|
|
|
|
|
|
|
use File::Temp;
|
|
|
|
use Fcntl qw/F_SETFD/;
|
|
|
|
|
2013-03-07 23:27:32 +00:00
|
|
|
*hashFile = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($algo, $base32, $path) = @_;
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-hash", "--flat", $path, "--type", $algo, $base32 ? "--base32" : ());
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*hashPath = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($algo, $base32, $path) = @_;
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-hash", $path, "--type", $algo, $base32 ? "--base32" : ());
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*hashString = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($algo, $base32, $s) = @_;
|
|
|
|
my $fh = File::Temp->new();
|
|
|
|
print $fh $s;
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-hash", $fh->filename, "--type", $algo, $base32 ? "--base32" : ());
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*addToStore = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($srcPath, $recursive, $algo) = @_;
|
|
|
|
die "not implemented" if $recursive || $algo ne "sha256";
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-store", "--add", $srcPath);
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*isValidPath = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($path) = @_;
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-store", "--check-validity", "--print-invalid", $path);
|
|
|
|
chomp $res;
|
|
|
|
return $res ne $path;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*queryPathHash = sub {
|
2012-05-10 23:03:23 +00:00
|
|
|
my ($path) = @_;
|
|
|
|
my $res = backtick("$Nix::Config::binDir/nix-store", "--query", "--hash", $path);
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
2013-03-07 23:27:32 +00:00
|
|
|
};
|
2012-05-10 23:03:23 +00:00
|
|
|
}
|
2011-10-10 18:12:40 +00:00
|
|
|
|
|
|
|
1;
|
|
|
|
__END__
|