libcryfs/tempfile/TempFile.cpp

32 lines
519 B
C++
Raw Normal View History

2015-04-25 02:40:02 +02:00
#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 (bf::exists(_path)) {
bf::remove(_path);
}
}
const bf::path &TempFile::path() const {
return _path;
}
}