#include "tempfile.h" #include #include #include #include namespace fs = std::filesystem; using namespace std::string_literals; fs::path Tempfile::GetPath() const { return m_path; } Tempfile::Tempfile() { try { char name[] = "/tmp/tempfileXXXXXX.zip"; int fd = mkstemps(name, 4); if (fd == -1) std::runtime_error("mkstemps: "s + strerror(errno)); close(fd); m_path = std::string{name}; } 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; } }