Fingerprint .timestamp, normalize use of Size / GetSize and make that function Fingerprint-aware

This commit is contained in:
Pepijn Schoen 2017-04-08 13:37:54 +02:00 committed by Patrick Niklaus
parent 802af08179
commit a196d5ced3
4 changed files with 18 additions and 20 deletions

View File

@ -47,7 +47,7 @@ class RasterGrid
storage::io::FileReader file_reader(filepath, storage::io::FileReader::HasNoFingerprint);
std::string buffer;
buffer.resize(file_reader.Size());
buffer.resize(file_reader.GetSize());
BOOST_ASSERT(buffer.size() > 1);

View File

@ -23,10 +23,6 @@ namespace io
class FileReader
{
private:
const boost::filesystem::path filepath;
boost::filesystem::ifstream input_stream;
public:
class LineWrapper : public std::string
{
@ -50,7 +46,7 @@ class FileReader
}
FileReader(const boost::filesystem::path &filepath_, const FingerprintFlag flag)
: filepath(filepath_)
: filepath(filepath_), fingerprint(flag)
{
input_stream.open(filepath, std::ios::binary);
if (!input_stream)
@ -75,7 +71,12 @@ class FileReader
// restore the current position
input_stream.seekg(positon, std::ios::beg);
return file_size;
if(fingerprint == FingerprintFlag::VerifyFingerprint) {
return std::size_t(file_size) - sizeof(util::FingerPrint);
} else {
return file_size;
}
}
/* Read count objects of type T into pointer dest */
@ -164,14 +165,11 @@ class FileReader
return true;
}
std::size_t Size()
{
auto current_pos = input_stream.tellg();
input_stream.seekg(0, input_stream.end);
auto length = input_stream.tellg();
input_stream.seekg(current_pos, input_stream.beg);
return length;
}
private:
const boost::filesystem::path filepath;
boost::filesystem::ifstream input_stream;
FingerprintFlag fingerprint;
};
class FileWriter

View File

@ -168,7 +168,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
util::Log() << "timestamp: " << timestamp;
storage::io::FileWriter timestamp_file(config.timestamp_file_name,
storage::io::FileWriter::HasNoFingerprint);
storage::io::FileWriter::GenerateFingerprint);
timestamp_file.WriteFrom(timestamp.c_str(), timestamp.length());

View File

@ -284,8 +284,8 @@ void Storage::PopulateLayout(DataLayout &layout)
// read timestampsize
{
io::FileReader timestamp_file(config.timestamp_path, io::FileReader::HasNoFingerprint);
const auto timestamp_size = timestamp_file.Size();
io::FileReader timestamp_file(config.timestamp_path, io::FileReader::VerifyFingerprint);
const auto timestamp_size = timestamp_file.GetSize();
layout.SetBlockSize<char>(DataLayout::TIMESTAMP, timestamp_size);
}
@ -720,8 +720,8 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
// store timestamp
{
io::FileReader timestamp_file(config.timestamp_path, io::FileReader::HasNoFingerprint);
const auto timestamp_size = timestamp_file.Size();
io::FileReader timestamp_file(config.timestamp_path, io::FileReader::VerifyFingerprint);
const auto timestamp_size = timestamp_file.GetSize();
const auto timestamp_ptr =
layout.GetBlockPtr<char, true>(memory_ptr, DataLayout::TIMESTAMP);