forked from lix-project/lix
* tmpnam() -> File::Temp::tempdir().
This commit is contained in:
parent
34427a7b43
commit
d98f750fd8
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use readmanifest;
|
use readmanifest;
|
||||||
use POSIX qw(tmpnam strftime);
|
use POSIX qw(strftime);
|
||||||
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
my $manifestDir = "@localstatedir@/nix/manifests";
|
my $manifestDir = "@localstatedir@/nix/manifests";
|
||||||
my $logFile = "@localstatedir@/log/nix/downloads";
|
my $logFile = "@localstatedir@/log/nix/downloads";
|
||||||
|
@ -12,9 +13,8 @@ open LOGFILE, ">>$logFile" or die "cannot open log file $logFile";
|
||||||
delete $ENV{"NIX_ROOT"};
|
delete $ENV{"NIX_ROOT"};
|
||||||
|
|
||||||
# Create a temporary directory.
|
# Create a temporary directory.
|
||||||
my $tmpDir;
|
my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpDir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpDir, 0700;
|
|
||||||
|
|
||||||
chdir $tmpDir or die "cannot change to `$tmpDir': $!";
|
chdir $tmpDir or die "cannot change to `$tmpDir': $!";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
>#! @perl@ -w -I@libexecdir@/nix
|
#! @perl@ -w -I@libexecdir@/nix
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
use readmanifest;
|
use readmanifest;
|
||||||
|
|
||||||
die unless scalar @ARGV == 5;
|
die unless scalar @ARGV == 5;
|
||||||
|
@ -14,13 +14,12 @@ my $patchesURL = $ARGV[2];
|
||||||
my $srcDir = $ARGV[3];
|
my $srcDir = $ARGV[3];
|
||||||
my $dstDir = $ARGV[4];
|
my $dstDir = $ARGV[4];
|
||||||
|
|
||||||
my $tmpdir;
|
my $tmpDir = tempdir("nix-generate-patches.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpdir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpdir, 0777;
|
|
||||||
|
|
||||||
print "TEMP = $tmpdir\n";
|
print "TEMP = $tmpDir\n";
|
||||||
|
|
||||||
#END { rmdir $tmpdir; }
|
#END { rmdir $tmpDir; }
|
||||||
|
|
||||||
my %srcNarFiles;
|
my %srcNarFiles;
|
||||||
my %srcPatches;
|
my %srcPatches;
|
||||||
|
@ -280,35 +279,35 @@ foreach my $p (keys %dstOutPaths) {
|
||||||
|
|
||||||
my $maxNarSize = 150 * 1024 * 1024;
|
my $maxNarSize = 150 * 1024 * 1024;
|
||||||
|
|
||||||
system("@bunzip2@ < $srcNarBz2 > $tmpdir/A") == 0
|
system("@bunzip2@ < $srcNarBz2 > $tmpDir/A") == 0
|
||||||
or die "cannot unpack $srcNarBz2";
|
or die "cannot unpack $srcNarBz2";
|
||||||
|
|
||||||
if ((stat "$tmpdir/A")[7] >= $maxNarSize) {
|
if ((stat "$tmpDir/A")[7] >= $maxNarSize) {
|
||||||
print " skipping, source is too large\n";
|
print " skipping, source is too large\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
system("@bunzip2@ < $dstNarBz2 > $tmpdir/B") == 0
|
system("@bunzip2@ < $dstNarBz2 > $tmpDir/B") == 0
|
||||||
or die "cannot unpack $dstNarBz2";
|
or die "cannot unpack $dstNarBz2";
|
||||||
|
|
||||||
if ((stat "$tmpdir/B")[7] >= $maxNarSize) {
|
if ((stat "$tmpDir/B")[7] >= $maxNarSize) {
|
||||||
print " skipping, destination is too large\n";
|
print " skipping, destination is too large\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
system("@libexecdir@/bsdiff $tmpdir/A $tmpdir/B $tmpdir/DIFF") == 0
|
system("@libexecdir@/bsdiff $tmpDir/A $tmpDir/B $tmpDir/DIFF") == 0
|
||||||
or die "cannot compute binary diff";
|
or die "cannot compute binary diff";
|
||||||
|
|
||||||
my $baseHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpdir/A` or die;
|
my $baseHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/A` or die;
|
||||||
chomp $baseHash;
|
chomp $baseHash;
|
||||||
|
|
||||||
my $narHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpdir/B` or die;
|
my $narHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/B` or die;
|
||||||
chomp $narHash;
|
chomp $narHash;
|
||||||
|
|
||||||
my $narDiffHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpdir/DIFF` or die;
|
my $narDiffHash = `@bindir@/nix-hash --flat --type $hashAlgo --base32 $tmpDir/DIFF` or die;
|
||||||
chomp $narDiffHash;
|
chomp $narDiffHash;
|
||||||
|
|
||||||
my $narDiffSize = (stat "$tmpdir/DIFF")[7];
|
my $narDiffSize = (stat "$tmpDir/DIFF")[7];
|
||||||
my $dstNarBz2Size = (stat $dstNarBz2)[7];
|
my $dstNarBz2Size = (stat $dstNarBz2)[7];
|
||||||
|
|
||||||
if ($narDiffSize >= $dstNarBz2Size) {
|
if ($narDiffSize >= $dstNarBz2Size) {
|
||||||
|
@ -327,7 +326,7 @@ foreach my $p (keys %dstOutPaths) {
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
system("cp '$tmpdir/DIFF' '$patchesDir/$finalName.tmp'") == 0
|
system("cp '$tmpDir/DIFF' '$patchesDir/$finalName.tmp'") == 0
|
||||||
or die "cannot copy diff";
|
or die "cannot copy diff";
|
||||||
|
|
||||||
rename("$patchesDir/$finalName.tmp", "$patchesDir/$finalName")
|
rename("$patchesDir/$finalName.tmp", "$patchesDir/$finalName")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! @perl@ -w
|
#! @perl@ -w
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
|
|
||||||
sub usageError {
|
sub usageError {
|
||||||
|
@ -65,10 +65,8 @@ if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my $tmpDir;
|
my $tmpDir = tempdir("nix-install-package.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpDir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpDir, 0777;
|
|
||||||
END { if (defined $tmpDir) { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; } }
|
|
||||||
|
|
||||||
|
|
||||||
sub barf {
|
sub barf {
|
||||||
|
|
|
@ -9,15 +9,14 @@
|
||||||
# directory.
|
# directory.
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"};
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
$binDir = "@bindir@" unless defined $binDir;
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
my $tmpDir;
|
my $tmpDir = tempdir("nix-pack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpDir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpDir, 0777;
|
|
||||||
END { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; }
|
|
||||||
mkdir "$tmpDir/contents", 0777 or die;
|
mkdir "$tmpDir/contents", 0777 or die;
|
||||||
mkdir "$tmpDir/references", 0777 or die;
|
mkdir "$tmpDir/references", 0777 or die;
|
||||||
mkdir "$tmpDir/derivers", 0777 or die;
|
mkdir "$tmpDir/derivers", 0777 or die;
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
#! @perl@ -w -I@libexecdir@/nix
|
#! @perl@ -w -I@libexecdir@/nix
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
use readmanifest;
|
use readmanifest;
|
||||||
|
|
||||||
my $tmpdir;
|
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpdir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpdir, 0777;
|
|
||||||
|
|
||||||
my $manifest = "$tmpdir/manifest";
|
my $manifest = "$tmpDir/manifest";
|
||||||
|
|
||||||
END { unlink $manifest; rmdir $tmpdir; }
|
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"};
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
$binDir = "@bindir@" unless defined $binDir;
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
#! @perl@ -w -I@libexecdir@/nix
|
#! @perl@ -w -I@libexecdir@/nix
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
use readmanifest;
|
use readmanifest;
|
||||||
|
|
||||||
my $hashAlgo = "sha256";
|
my $hashAlgo = "sha256";
|
||||||
|
|
||||||
my $tmpdir;
|
my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpdir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpdir, 0777;
|
|
||||||
|
|
||||||
my $nixfile = "$tmpdir/create-nars.nix";
|
my $nixExpr = "$tmpDir/create-nars.nix";
|
||||||
my $manifest = "$tmpdir/MANIFEST";
|
my $manifest = "$tmpDir/MANIFEST";
|
||||||
|
|
||||||
END { unlink $manifest; unlink $nixfile; rmdir $tmpdir; }
|
|
||||||
|
|
||||||
my $curl = "@curl@ --fail --silent";
|
my $curl = "@curl@ --fail --silent";
|
||||||
my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
|
my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
|
||||||
|
@ -101,7 +98,7 @@ my @storePaths = keys %storePaths;
|
||||||
|
|
||||||
# For each path, create a Nix expression that turns the path into
|
# For each path, create a Nix expression that turns the path into
|
||||||
# a Nix archive.
|
# a Nix archive.
|
||||||
open NIX, ">$nixfile";
|
open NIX, ">$nixExpr";
|
||||||
print NIX "[";
|
print NIX "[";
|
||||||
|
|
||||||
foreach my $storePath (@storePaths) {
|
foreach my $storePath (@storePaths) {
|
||||||
|
@ -122,7 +119,7 @@ close NIX;
|
||||||
# Instantiate store expressions from the Nix expression.
|
# Instantiate store expressions from the Nix expression.
|
||||||
my @storeExprs;
|
my @storeExprs;
|
||||||
print STDERR "instantiating store expressions...\n";
|
print STDERR "instantiating store expressions...\n";
|
||||||
my $pid = open(READ, "$binDir/nix-instantiate $nixfile|")
|
my $pid = open(READ, "$binDir/nix-instantiate $nixExpr|")
|
||||||
or die "cannot run nix-instantiate";
|
or die "cannot run nix-instantiate";
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
chomp;
|
chomp;
|
||||||
|
|
|
@ -7,15 +7,13 @@
|
||||||
# directory.
|
# directory.
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX qw(tmpnam);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"};
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
$binDir = "@bindir@" unless defined $binDir;
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
my $tmpDir;
|
my $tmpDir = tempdir("nix-unpack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
do { $tmpDir = tmpnam(); }
|
or die "cannot create a temporary directory";
|
||||||
until mkdir $tmpDir, 0777;
|
|
||||||
END { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; }
|
|
||||||
|
|
||||||
|
|
||||||
# Unpack the NAR archive on standard input.
|
# Unpack the NAR archive on standard input.
|
||||||
|
|
Loading…
Reference in a new issue