From: Mikko Rasa Date: Sat, 16 Sep 2023 09:50:22 +0000 (+0300) Subject: Don't delete the temporary file while it's in use X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=95530ecf5c8e48080dcad76cdd3a9e71c9feefca;p=libs%2Fdatafile.git Don't delete the temporary file while it's in use That doesn't work on Windows. --- diff --git a/tool/packer.cpp b/tool/packer.cpp index ae88ada..3f175d9 100644 --- a/tool/packer.cpp +++ b/tool/packer.cpp @@ -14,10 +14,10 @@ using namespace Msp; Packer::Packer(DataTool &t): tool(t), - tmp_file(tempfile()) + tmp_file(tempfile(tmp_path)) { } -IO::BufferedFile *Packer::tempfile() +IO::BufferedFile *Packer::tempfile(FS::Path &out_fn) { FS::Path tmpdir = FS::get_temp_dir(); @@ -27,7 +27,7 @@ IO::BufferedFile *Packer::tempfile() { FS::Path filename = tmpdir/format("mspdatatool.%d", i); IO::BufferedFile *file = new IO::BufferedFile(filename.str(), IO::M_RDWR, IO::File::C_NEW); - FS::unlink(filename.str()); + out_fn = filename; return file; } catch(const IO::file_already_exists &) @@ -40,6 +40,7 @@ IO::BufferedFile *Packer::tempfile() Packer::~Packer() { delete tmp_file; + FS::unlink(tmp_path); } void Packer::pack_file(const string &fn) diff --git a/tool/packer.h b/tool/packer.h index b89f073..141a2a1 100644 --- a/tool/packer.h +++ b/tool/packer.h @@ -20,6 +20,7 @@ private: typedef std::list ObjectList; DataTool &tool; + Msp::FS::Path tmp_path; Msp::IO::BufferedFile *tmp_file = nullptr; std::list directory; unsigned dir_alloc = 0; @@ -27,7 +28,7 @@ private: public: Packer(DataTool &); private: - static Msp::IO::BufferedFile *tempfile(); + static Msp::IO::BufferedFile *tempfile(Msp::FS::Path &); public: ~Packer();