diff options
Diffstat (limited to 'perl')
-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 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"; +} |