diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-13 23:12:57 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-13 23:12:57 +0200 |
commit | 3bea429ae8190565978104db3dbbb5e1a53fc018 (patch) | |
tree | 480747e11f2af030700075e2ad6c6677cdc2f4f1 /perl/lib/Nix/Utils.pm | |
parent | fde819f2e22e0fb84dc6d8fc4602a00577137d0a (diff) |
Use $XDG_RUNTIME_DIR for temporary files
Diffstat (limited to 'perl/lib/Nix/Utils.pm')
-rw-r--r-- | perl/lib/Nix/Utils.pm | 10 |
1 files changed, 9 insertions, 1 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"; +} |