libcryfs/tempfile/TempFile.cpp
2015-10-23 12:15:51 +02:00

36 lines
573 B
C++

#include "TempFile.h"
#include <fstream>
namespace bf = boost::filesystem;
using std::ofstream;
namespace cpputils {
TempFile::TempFile(const bf::path &path, bool create)
: _path(path) {
if (create) {
ofstream file(_path.c_str());
}
}
TempFile::TempFile(bool create)
: TempFile(bf::unique_path(bf::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%"), create) {
}
TempFile::~TempFile() {
if (exists()) {
bf::remove(_path);
}
}
bool TempFile::exists() const {
return bf::exists(_path);
}
const bf::path &TempFile::path() const {
return _path;
}
}