This commit is contained in:
@ -40,7 +40,7 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
if (not fileOrDir.is_regular_file(e)) {
|
||||
continue;
|
||||
}
|
||||
dumpParams.fileSize = std::filesystem::file_size(dumpParams.dirEntry.path(), e);
|
||||
dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e);
|
||||
if (e) {
|
||||
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
|
||||
continue;
|
||||
@ -54,7 +54,7 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
if (dumpParams.fileSize > fileBuf.size()) {
|
||||
sif::error << "PersistentTmStore: File too large, is deleted" << std::endl;
|
||||
triggerEvent(persTmStore::FILE_TOO_LARGE, dumpParams.fileSize, fileBuf.size());
|
||||
std::filesystem::remove(dumpParams.dirEntry.path(), e);
|
||||
std::filesystem::remove(fileOrDir.path(), e);
|
||||
continue;
|
||||
}
|
||||
const path& file = fileOrDir.path();
|
||||
@ -73,9 +73,9 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Check whether this is a suffixed file.
|
||||
DumpIndex dumpIndex;
|
||||
dumpIndex.epoch = fileEpoch;
|
||||
dumpIndex.suffixIdx = extractSuffix(file.string());
|
||||
dumpParams.orderedDumpFilestamps.emplace(dumpIndex);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
@ -83,6 +83,21 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
uint8_t PersistentTmStore::extractSuffix(const std::string& pathStr) {
|
||||
std::string numberStr;
|
||||
// Find the position of the dot at the end of the file path
|
||||
size_t dotPos = pathStr.find_last_of('.');
|
||||
if (dotPos != std::string::npos && dotPos < pathStr.length() - 1) {
|
||||
// Extract the substring after the dot
|
||||
numberStr = pathStr.substr(dotPos + 1);
|
||||
}
|
||||
int number = std::stoi(numberStr);
|
||||
if (number < 0 or number > std::numeric_limits<uint8_t>::max()) {
|
||||
return 0;
|
||||
}
|
||||
return static_cast<uint8_t>(number);
|
||||
}
|
||||
|
||||
ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() {
|
||||
if (not activeFile.has_value()) {
|
||||
return createMostRecentFile(std::nullopt);
|
||||
@ -271,12 +286,14 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
|
||||
tv.tv_sec = dumpIndex.epoch;
|
||||
size_t fullPathLength = 0;
|
||||
createFileName(tv, dumpIndex.suffixIdx, fullPathLength);
|
||||
path filePath(std::string(reinterpret_cast<const char*>(filePathBuf.data()), fullPathLength));
|
||||
std::ifstream ifile(filePath, std::ios::binary);
|
||||
dumpParams.currentFile =
|
||||
path(std::string(reinterpret_cast<const char*>(filePathBuf.data()), fullPathLength));
|
||||
std::ifstream ifile(dumpParams.currentFile, std::ios::binary);
|
||||
if (ifile.bad()) {
|
||||
sif::error << "PersistentTmStore: File is bad" << std::endl;
|
||||
continue;
|
||||
}
|
||||
sif::debug << baseName << " dump: Loading " << dumpParams.currentFile << std::endl;
|
||||
ifile.read(reinterpret_cast<char*>(fileBuf.data()),
|
||||
static_cast<std::streamsize>(dumpParams.fileSize));
|
||||
// Increment iterator for next cycle.
|
||||
@ -303,8 +320,8 @@ ReturnValue_t PersistentTmStore::getNextDumpPacket(PusTmReader& reader, bool& fi
|
||||
// Delete the file and load next. Could use better algorithm to partially
|
||||
// restore the file dump, but for now do not trust the file.
|
||||
std::error_code e;
|
||||
std::filesystem::remove(dumpParams.dirEntry.path().c_str(), e);
|
||||
if (dumpParams.dirEntry.path() == activeFile) {
|
||||
std::filesystem::remove(dumpParams.currentFile.c_str(), e);
|
||||
if (dumpParams.currentFile == activeFile) {
|
||||
activeFile == std::nullopt;
|
||||
assignAndOrCreateMostRecentFile();
|
||||
}
|
||||
|
Reference in New Issue
Block a user