2015-04-25 02:40:02 +02:00
|
|
|
#include "TempDir.h"
|
2015-10-30 18:27:40 +01:00
|
|
|
#include "../logging/logging.h"
|
2015-04-25 02:40:02 +02:00
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
2015-10-30 18:27:40 +01:00
|
|
|
using namespace cpputils::logging;
|
2015-04-25 02:40:02 +02:00
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
|
|
|
|
TempDir::TempDir()
|
2015-10-30 18:27:40 +01:00
|
|
|
: _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() {
|
2015-10-30 18:27:40 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|