Use $XDG_RUNTIME_DIR for temporary files

This commit is contained in:
Eelco Dolstra 2014-08-13 23:12:57 +02:00
parent fde819f2e2
commit 3bea429ae8
8 changed files with 16 additions and 23 deletions

View file

@ -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";
}

View file

@ -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";

View file

@ -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";

View file

@ -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;

View file

@ -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 {

View file

@ -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:\/\//) {

View file

@ -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;

View file

@ -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";