summaryrefslogtreecommitdiffhomepage
path: root/libcommon/tempfile.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-05-16 13:28:52 +0200
committerRoland Reichwein <mail@reichwein.it>2020-05-16 13:28:52 +0200
commit6b2a9dabbfad4d64268967a32dff0f1dc55763de (patch)
treeb3a1f68d8b44090b98ac3bdcf1c8423ebc08c846 /libcommon/tempfile.cpp
parent83b25165218281c2a2e98b5e72a0375a7e6a71ca (diff)
Makefile cleanup, included missing files
Diffstat (limited to 'libcommon/tempfile.cpp')
-rw-r--r--libcommon/tempfile.cpp27
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;
+ }
+}