From 6b2a9dabbfad4d64268967a32dff0f1dc55763de Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 16 May 2020 13:28:52 +0200 Subject: Makefile cleanup, included missing files --- libcommon/tempfile.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 libcommon/tempfile.cpp (limited to 'libcommon/tempfile.cpp') diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp new file mode 100644 index 0000000..5d3a086 --- /dev/null +++ b/libcommon/tempfile.cpp @@ -0,0 +1,27 @@ +#include "tempfile.h" + +#include + +namespace fs = std::filesystem; +using namespace std::string_literals; + +fs::path Tempfile::GetPath() const +{ + return m_path; +} + +Tempfile::Tempfile() { + try { + m_path = std::string{tmpnam(NULL)} + ".zip"s; + } catch (const std::exception& ex) { + throw std::runtime_error("Tempfile error: "s + ex.what()); + } +} + +Tempfile::~Tempfile() { + try { + fs::remove_all(m_path); + } catch (const std::exception& ex) { + std::cerr << "Warning: Couldn't remove temporary file " << m_path << std::endl; + } +} -- cgit v1.2.3