Truncate the file used for the region mapping

This commit is contained in:
Alexey Rybalchenko 2020-04-28 19:17:47 +02:00
parent 960b612d80
commit 5a49c5b9b1

View File

@ -19,6 +19,7 @@
#include <cerrno> #include <cerrno>
#include <chrono> #include <chrono>
#include <ios>
using namespace std; using namespace std;
@ -49,7 +50,17 @@ Region::Region(Manager& manager, uint64_t id, uint64_t size, bool remote, Region
if (path != "") { if (path != "") {
fName = string(path + fName); fName = string(path + fName);
fFile = fopen(fName.c_str(), fRemote ? "r+" : "w+"); if (!fRemote) {
// create a file
filebuf fbuf;
if (fbuf.open(fName, ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary)) {
// set the size
fbuf.pubseekoff(size - 1, ios_base::beg);
fbuf.sputc(0);
}
}
fFile = fopen(fName.c_str(), "r+");
if (!fFile) { if (!fFile) {
LOG(error) << "Failed to initialize file: " << fName; LOG(error) << "Failed to initialize file: " << fName;