about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-13T21·12+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-13T21·12+0200
commit3bea429ae8190565978104db3dbbb5e1a53fc018 (patch)
tree480747e11f2af030700075e2ad6c6677cdc2f4f1
parentfde819f2e22e0fb84dc6d8fc4602a00577137d0a (diff)
Use $XDG_RUNTIME_DIR for temporary files
-rw-r--r--perl/lib/Nix/Utils.pm10
-rwxr-xr-xscripts/download-using-manifests.pl.in4
-rwxr-xr-xscripts/nix-build.in4
-rwxr-xr-xscripts/nix-generate-patches.in5
-rwxr-xr-xscripts/nix-install-package.in4
-rwxr-xr-xscripts/nix-prefetch-url.in4
-rwxr-xr-xscripts/nix-pull.in4
-rwxr-xr-xscripts/nix-push.in4
8 files changed, 16 insertions, 23 deletions
diff --git a/perl/lib/Nix/Utils.pm b/perl/lib/Nix/Utils.pm
index 78d3db54270d..05cd92b8ea0d 100644
--- a/perl/lib/Nix/Utils.pm
+++ b/perl/lib/Nix/Utils.pm
@@ -1,7 +1,9 @@
 package Nix::Utils;
 
+use File::Temp qw(tempdir);
+
 our @ISA = qw(Exporter);
-our @EXPORT = qw(checkURL uniq writeFile readFile);
+our @EXPORT = qw(checkURL uniq writeFile readFile mkTempDir);
 
 $urlRE = "(?: [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*]+ )";
 
@@ -36,3 +38,9 @@ sub readFile {
     close TMP or die;
     return $s;
 }
+
+sub mkTempDir {
+    my ($name) = @_;
+    return tempdir("$name.XXXXXX", CLEANUP => 1, DIR => $ENV{"TMPDIR"} // $ENV{"XDG_RUNTIME_DIR"} // "/tmp")
+        or die "cannot create a temporary directory";
+}
diff --git a/scripts/download-using-manifests.pl.in b/scripts/download-using-manifests.pl.in
index b670163038e1..de63aec5713f 100755
--- a/scripts/download-using-manifests.pl.in
+++ b/scripts/download-using-manifests.pl.in
@@ -6,7 +6,6 @@ use Nix::Manifest;
 use Nix::Store;
 use Nix::Utils;
 use POSIX qw(strftime);
-use File::Temp qw(tempdir);
 
 STDOUT->autoflush(1);
 
@@ -247,8 +246,7 @@ $fast = 0;
 
 
 # Create a temporary directory.
-my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir("nix-download");
 
 my $tmpNar = "$tmpDir/nar";
 my $tmpNar2 = "$tmpDir/nar2";
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index 74307a5baf1c..cf7efa891949 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -4,7 +4,6 @@ use strict;
 use Nix::Config;
 use Nix::Store;
 use Nix::Utils;
-use File::Temp qw(tempdir);
 
 
 my $dryRun = 0;
@@ -25,8 +24,7 @@ my @envExclude = ();
 my $myName = $runEnv ? "nix-shell" : "nix-build";
 
 
-my $tmpDir = tempdir("$myName.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir($myName);
 
 my $outLink = "./result";
 my $drvLink = "$tmpDir/derivation";
diff --git a/scripts/nix-generate-patches.in b/scripts/nix-generate-patches.in
index 969af916d8e6..0a29c0548c1f 100755
--- a/scripts/nix-generate-patches.in
+++ b/scripts/nix-generate-patches.in
@@ -1,9 +1,9 @@
 #! @perl@ -w @perlFlags@
 
 use strict;
-use File::Temp qw(tempdir);
 use Nix::Manifest;
 use Nix::GeneratePatches;
+use Nix::Utils;
 
 if (scalar @ARGV != 5) {
     print STDERR <<EOF;
@@ -31,8 +31,7 @@ readManifest $srcManifest, \%srcNarFiles, \%srcPatches;
 my (%dstNarFiles, %dstLocalPaths, %dstPatches);
 readManifest $dstManifest, \%dstNarFiles, \%dstPatches;
 
-my $tmpDir = tempdir("nix-generate-patches.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir("nix-generate-patches");
 
 generatePatches \%srcNarFiles, \%dstNarFiles, \%srcPatches, \%dstPatches,
     $narPath, $patchesPath, $patchesURL, $tmpDir;
diff --git a/scripts/nix-install-package.in b/scripts/nix-install-package.in
index 9414541d1fbc..a3187c72169b 100755
--- a/scripts/nix-install-package.in
+++ b/scripts/nix-install-package.in
@@ -1,7 +1,6 @@
 #! @perl@ -w @perlFlags@
 
 use strict;
-use File::Temp qw(tempdir);
 use Nix::Config;
 use Nix::Utils;
 
@@ -50,8 +49,7 @@ if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
 }
 
 
-my $tmpDir = tempdir("nix-install-package.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir("nix-install-package");
 
 
 sub barf {
diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in
index bcd9197bcff1..24753bd5b9bd 100755
--- a/scripts/nix-prefetch-url.in
+++ b/scripts/nix-prefetch-url.in
@@ -2,7 +2,6 @@
 
 use strict;
 use File::Basename;
-use File::Temp qw(tempdir);
 use File::stat;
 use Nix::Store;
 use Nix::Config;
@@ -38,8 +37,7 @@ EOF
     exit 1;
 }
 
-my $tmpDir = tempdir("nix-prefetch-url.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir("nix-prefetch-url");
 
 # Hack to support the mirror:// scheme from Nixpkgs.
 if ($url =~ /^mirror:\/\//) {
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in
index 58dd2cf27eee..77fb33ba58e0 100755
--- a/scripts/nix-pull.in
+++ b/scripts/nix-pull.in
@@ -1,13 +1,9 @@
 #! @perl@ -w @perlFlags@
 
 use strict;
-use File::Temp qw(tempdir);
 use Nix::Config;
 use Nix::Manifest;
 
-my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
-
 my $manifestDir = $Nix::Config::manifestDir;
 
 
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index bdd128a6f5c2..1343099f1dbf 100755
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -2,7 +2,6 @@
 
 use strict;
 use File::Basename;
-use File::Temp qw(tempdir);
 use File::Path qw(mkpath);
 use File::stat;
 use File::Copy;
@@ -12,8 +11,7 @@ use Nix::Manifest;
 use Nix::Utils;
 use Nix::Crypto;
 
-my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
-    or die "cannot create a temporary directory";
+my $tmpDir = mkTempDir("nix-push");
 
 my $nixExpr = "$tmpDir/create-nars.nix";