From ffbc4b86547b788225895a868b48d602cb1bc139 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 3 Jun 2019 11:20:23 +0300 Subject: [PATCH] Respect the TMPDIR environment variable when creating data packs --- tool/packer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tool/packer.cpp b/tool/packer.cpp index 3576472..46dd5d2 100644 --- a/tool/packer.cpp +++ b/tool/packer.cpp @@ -19,17 +19,20 @@ Packer::Packer(DataTool &t): IO::File *Packer::tempfile() { + FS::Path tmpdir; + const char *tmp_env = getenv("TMPDIR"); + if(tmp_env) + tmpdir = tmp_env; + else + tmpdir = "/tmp"; + for(unsigned i=0;; ++i) { try { - std::string filename = format("/tmp/mspdatatool.%d", i); - /*filename.reserve(25); - filename.append("/tmp/mspdatatool."); - for(unsigned i=0; i<8; ++i) - filename.append(rand());*/ - IO::File *file = new IO::File(filename, IO::M_RDWR, IO::File::C_NEW); - FS::unlink(filename); + FS::Path filename = tmpdir/format("mspdatatool.%d", i); + IO::File *file = new IO::File(filename.str(), IO::M_RDWR, IO::File::C_NEW); + FS::unlink(filename.str()); return file; } catch(const IO::file_already_exists &) -- 2.43.0