From 3bea429ae8190565978104db3dbbb5e1a53fc018 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Aug 2014 23:12:57 +0200 Subject: [PATCH] Use $XDG_RUNTIME_DIR for temporary files --- perl/lib/Nix/Utils.pm | 10 +++++++++- scripts/download-using-manifests.pl.in | 4 +--- scripts/nix-build.in | 4 +--- scripts/nix-generate-patches.in | 5 ++--- scripts/nix-install-package.in | 4 +--- scripts/nix-prefetch-url.in | 4 +--- scripts/nix-pull.in | 4 ---- scripts/nix-push.in | 4 +--- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/perl/lib/Nix/Utils.pm b/perl/lib/Nix/Utils.pm index 78d3db542..05cd92b8e 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 b67016303..de63aec57 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 74307a5ba..cf7efa891 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 969af916d..0a29c0548 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 < 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 9414541d1..a3187c721 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 bcd9197bc..24753bd5b 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 58dd2cf27..77fb33ba5 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 bdd128a6f..1343099f1 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";