about summary refs log tree commit diff
path: root/perl/lib
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 /perl/lib
parentfde819f2e22e0fb84dc6d8fc4602a00577137d0a (diff)
Use $XDG_RUNTIME_DIR for temporary files
Diffstat (limited to 'perl/lib')
-rw-r--r--perl/lib/Nix/Utils.pm10
1 files changed, 9 insertions, 1 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";
+}