aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/download-using-manifests.pl.in8
-rwxr-xr-xscripts/generate-patches.pl.in33
-rw-r--r--scripts/nix-install-package.in8
-rw-r--r--scripts/nix-pack-closure.in9
-rw-r--r--scripts/nix-pull.in11
-rw-r--r--scripts/nix-push.in17
-rw-r--r--scripts/nix-unpack-closure.in8
7 files changed, 41 insertions, 53 deletions
diff --git a/scripts/download-using-manifests.pl.in b/scripts/download-using-manifests.pl.in
index 5dd5b817a..c5400a901 100644
--- a/scripts/download-using-manifests.pl.in
+++ b/scripts/download-using-manifests.pl.in
@@ -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': $!";
diff --git a/scripts/generate-patches.pl.in b/scripts/generate-patches.pl.in
index bdb6d513c..3a35b8518 100755
--- a/scripts/generate-patches.pl.in
+++ b/scripts/generate-patches.pl.in
@@ -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")
diff --git a/scripts/nix-install-package.in b/scripts/nix-install-package.in
index dc46c8cb2..bb72601eb 100644
--- a/scripts/nix-install-package.in
+++ b/scripts/nix-install-package.in
@@ -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 {
diff --git a/scripts/nix-pack-closure.in b/scripts/nix-pack-closure.in
index ebf716407..6c0e85d2a 100644
--- a/scripts/nix-pack-closure.in
+++ b/scripts/nix-pack-closure.in
@@ -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;
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in
index c7c20fb9b..c1382b442 100644
--- a/scripts/nix-pull.in
+++ b/scripts/nix-pull.in
@@ -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;
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index 02b1dec48..e5bd404a2 100644
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -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;
diff --git a/scripts/nix-unpack-closure.in b/scripts/nix-unpack-closure.in
index 20fdef759..89e7aa24d 100644
--- a/scripts/nix-unpack-closure.in
+++ b/scripts/nix-unpack-closure.in
@@ -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.