From 18b67d18a72a4c224c0bd0bff3ca57a9305ed77f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 24 Jun 2023 02:07:11 +0200 Subject: [PATCH] seems to work now --- mission/tmtc/PersistentTmStore.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/mission/tmtc/PersistentTmStore.cpp b/mission/tmtc/PersistentTmStore.cpp index f4ce65ef..6a92cdf1 100644 --- a/mission/tmtc/PersistentTmStore.cpp +++ b/mission/tmtc/PersistentTmStore.cpp @@ -40,7 +40,6 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t if (not fileOrDir.is_regular_file(e)) { continue; } - sif::debug << "Path: " << fileOrDir.path() << std::endl; dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e); if (e) { sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl; @@ -76,8 +75,8 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t DumpIndex dumpIndex; dumpIndex.epoch = fileEpoch; dumpIndex.suffixIdx = extractSuffix(file.string()); + // sif::debug << "Inserting file " << fileOrDir.path() << std::endl; dumpParams.orderedDumpFilestamps.emplace(dumpIndex); - return returnvalue::OK; } } return returnvalue::OK; @@ -87,10 +86,11 @@ std::optional PersistentTmStore::extractSuffix(const std::string& pathS 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); + if ((dotPos < pathStr.length()) and not std::isdigit(pathStr[dotPos + 1])) { + return std::nullopt; } + // Extract the substring after the dot + numberStr = pathStr.substr(dotPos + 1); std::optional number; try { number = std::stoi(numberStr); @@ -202,7 +202,6 @@ ReturnValue_t PersistentTmStore::storePacket(PusTmReader& reader) { createMostRecentFile(suffix); } - sif::debug << "active file " << activeFile.value() << std::endl; // Rollover conditions were handled, write to file now std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary); of.write(reinterpret_cast(reader.getFullData()), @@ -298,12 +297,19 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() { createFileName(tv, dumpIndex.suffixIdx, fullPathLength); dumpParams.currentFile = path(std::string(reinterpret_cast(filePathBuf.data()), fullPathLength)); - std::ifstream ifile(dumpParams.currentFile, std::ios::binary); - if (ifile.bad()) { - sif::error << "PersistentTmStore: File is bad" << std::endl; + dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e); + if (e) { + // TODO: Event? + sif::error << "PersistentTmStore: Could not load next dump file: " << e.message() + << std::endl; continue; } - sif::debug << baseName << " dump: Loading " << dumpParams.currentFile << std::endl; + std::ifstream ifile(dumpParams.currentFile, std::ios::binary); + if (ifile.bad()) { + sif::error << "PersistentTmStore: File is bad. Loading next file" << std::endl; + continue; + } + // sif::debug << baseName << " dump: Loading " << dumpParams.currentFile << std::endl; ifile.read(reinterpret_cast(fileBuf.data()), static_cast(dumpParams.fileSize)); // Increment iterator for next cycle. @@ -368,7 +374,6 @@ ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional suf size_t currentIdx; createFileName(currentTv, suffix, currentIdx); path newPath(std::string(reinterpret_cast(filePathBuf.data()), currentIdx)); - sif::debug << "creating new file: " << newPath << std::endl; std::ofstream of(newPath, std::ios::binary); activeFile = newPath; activeFileTv = currentTv;