* tmpnam() -> File::Temp::tempdir().

This commit is contained in:
Eelco Dolstra 2006-10-04 18:58:11 +00:00
parent 34427a7b43
commit d98f750fd8
7 changed files with 41 additions and 53 deletions

View file

@ -2,7 +2,8 @@
use strict;
use readmanifest;
use POSIX qw(tmpnam strftime);
use POSIX qw(strftime);
use File::Temp qw(tempdir);
my $manifestDir = "@localstatedir@/nix/manifests";
my $logFile = "@localstatedir@/log/nix/downloads";
@ -12,9 +13,8 @@ open LOGFILE, ">>$logFile" or die "cannot open log file $logFile";
delete $ENV{"NIX_ROOT"};
# Create a temporary directory.
my $tmpDir;
do { $tmpDir = tmpnam(); }
until mkdir $tmpDir, 0700;
my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
chdir $tmpDir or die "cannot change to `$tmpDir': $!";

View file

@ -1,7 +1,7 @@
>#! @perl@ -w -I@libexecdir@/nix
#! @perl@ -w -I@libexecdir@/nix
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
use readmanifest;
die unless scalar @ARGV == 5;
@ -14,13 +14,12 @@ my $patchesURL = $ARGV[2];
my $srcDir = $ARGV[3];
my $dstDir = $ARGV[4];
my $tmpdir;
do { $tmpdir = tmpnam(); }
until mkdir $tmpdir, 0777;
my $tmpDir = tempdir("nix-generate-patches.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
print "TEMP = $tmpdir\n";
print "TEMP = $tmpDir\n";
#END { rmdir $tmpdir; }
#END { rmdir $tmpDir; }
my %srcNarFiles;
my %srcPatches;
@ -280,35 +279,35 @@ foreach my $p (keys %dstOutPaths) {
my $maxNarSize = 150 * 1024 * 1024;
system("@bunzip2@ < $srcNarBz2 > $tmpdir/A") == 0
system("@bunzip2@ < $srcNarBz2 > $tmpDir/A") == 0
or die "cannot unpack $srcNarBz2";
if ((stat "$tmpdir/A")[7] >= $maxNarSize) {
if ((stat "$tmpDir/A")[7] >= $maxNarSize) {
print " skipping, source is too large\n";
next;
}
system("@bunzip2@ < $dstNarBz2 > $tmpdir/B") == 0
system("@bunzip2@ < $dstNarBz2 > $tmpDir/B") == 0
or die "cannot unpack $dstNarBz2";
if ((stat "$tmpdir/B")[7] >= $maxNarSize) {
if ((stat "$tmpDir/B")[7] >= $maxNarSize) {
print " skipping, destination is too large\n";
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";
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;
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;
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;
my $narDiffSize = (stat "$tmpdir/DIFF")[7];
my $narDiffSize = (stat "$tmpDir/DIFF")[7];
my $dstNarBz2Size = (stat $dstNarBz2)[7];
if ($narDiffSize >= $dstNarBz2Size) {
@ -327,7 +326,7 @@ foreach my $p (keys %dstOutPaths) {
else {
system("cp '$tmpdir/DIFF' '$patchesDir/$finalName.tmp'") == 0
system("cp '$tmpDir/DIFF' '$patchesDir/$finalName.tmp'") == 0
or die "cannot copy diff";
rename("$patchesDir/$finalName.tmp", "$patchesDir/$finalName")

View file

@ -1,7 +1,7 @@
#! @perl@ -w
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
sub usageError {
@ -65,10 +65,8 @@ if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
}
my $tmpDir;
do { $tmpDir = tmpnam(); }
until mkdir $tmpDir, 0777;
END { if (defined $tmpDir) { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; } }
my $tmpDir = tempdir("nix-install-package.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
sub barf {

View file

@ -9,15 +9,14 @@
# directory.
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
my $binDir = $ENV{"NIX_BIN_DIR"};
$binDir = "@bindir@" unless defined $binDir;
my $tmpDir;
do { $tmpDir = tmpnam(); }
until mkdir $tmpDir, 0777;
END { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; }
my $tmpDir = tempdir("nix-pack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
mkdir "$tmpDir/contents", 0777 or die;
mkdir "$tmpDir/references", 0777 or die;
mkdir "$tmpDir/derivers", 0777 or die;

View file

@ -1,16 +1,13 @@
#! @perl@ -w -I@libexecdir@/nix
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
use readmanifest;
my $tmpdir;
do { $tmpdir = tmpnam(); }
until mkdir $tmpdir, 0777;
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
my $manifest = "$tmpdir/manifest";
END { unlink $manifest; rmdir $tmpdir; }
my $manifest = "$tmpDir/manifest";
my $binDir = $ENV{"NIX_BIN_DIR"};
$binDir = "@bindir@" unless defined $binDir;

View file

@ -1,19 +1,16 @@
#! @perl@ -w -I@libexecdir@/nix
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
use readmanifest;
my $hashAlgo = "sha256";
my $tmpdir;
do { $tmpdir = tmpnam(); }
until mkdir $tmpdir, 0777;
my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
my $nixfile = "$tmpdir/create-nars.nix";
my $manifest = "$tmpdir/MANIFEST";
END { unlink $manifest; unlink $nixfile; rmdir $tmpdir; }
my $nixExpr = "$tmpDir/create-nars.nix";
my $manifest = "$tmpDir/MANIFEST";
my $curl = "@curl@ --fail --silent";
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
# a Nix archive.
open NIX, ">$nixfile";
open NIX, ">$nixExpr";
print NIX "[";
foreach my $storePath (@storePaths) {
@ -122,7 +119,7 @@ close NIX;
# Instantiate store expressions from the Nix expression.
my @storeExprs;
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";
while (<READ>) {
chomp;

View file

@ -7,15 +7,13 @@
# directory.
use strict;
use POSIX qw(tmpnam);
use File::Temp qw(tempdir);
my $binDir = $ENV{"NIX_BIN_DIR"};
$binDir = "@bindir@" unless defined $binDir;
my $tmpDir;
do { $tmpDir = tmpnam(); }
until mkdir $tmpDir, 0777;
END { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; }
my $tmpDir = tempdir("nix-unpack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
# Unpack the NAR archive on standard input.