diff options
Diffstat (limited to 'libcommon/tempfile.cpp')
-rw-r--r-- | libcommon/tempfile.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
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 <iostream> + +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; + } +} |