libcryfs/tempfile/TempDir.cpp

33 lines
588 B
C++
Raw Normal View History

2015-04-25 02:40:02 +02:00
#include "TempDir.h"
#include "../logging/logging.h"
2015-04-25 02:40:02 +02:00
namespace bf = boost::filesystem;
using namespace cpputils::logging;
2015-04-25 02:40:02 +02:00
namespace cpputils {
TempDir::TempDir()
: _path(bf::unique_path(bf::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%")) {
2015-04-25 02:40:02 +02:00
bf::create_directory(_path);
}
TempDir::~TempDir() {
2015-10-29 15:51:16 +01:00
remove();
}
void TempDir::remove() {
try {
if (bf::exists(_path)) {
bf::remove_all(_path);
}
} catch (const boost::filesystem::filesystem_error &e) {
LOG(ERROR) << "Could not delete tempfile.";
2015-10-29 15:51:16 +01:00
}
2015-04-25 02:40:02 +02:00
}
const bf::path &TempDir::path() const {
return _path;
}
}