This commit is contained in:
@ -28,35 +28,6 @@ PersistentTmStore::PersistentTmStore(object_id_t objectId, const char* baseDir,
|
||||
}
|
||||
|
||||
ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() {
|
||||
using namespace std::filesystem;
|
||||
for (auto const& file : directory_iterator(basePath)) {
|
||||
if (file.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
auto pathStr = file.path().string();
|
||||
if (pathStr.find(baseName) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
unsigned int underscorePos = pathStr.find_last_of('_');
|
||||
std::string stampStr = pathStr.substr(underscorePos + 1);
|
||||
struct tm time {};
|
||||
if (nullptr == strptime(stampStr.c_str(), FILE_DATE_FORMAT, &time)) {
|
||||
sif::error << "PersistentTmStore::assignOrCreateMostRecentFile: Error reading timestamp"
|
||||
<< std::endl;
|
||||
// Delete the file and re-create it.
|
||||
activeFile = std::nullopt;
|
||||
std::filesystem::remove(file.path());
|
||||
break;
|
||||
}
|
||||
time_t fileEpoch = timegm(&time);
|
||||
// There is still a file within the active time window, so re-use that file for new TMs to
|
||||
// store.
|
||||
if (fileEpoch + static_cast<time_t>(rolloverDiffSeconds) > currentTv.tv_sec) {
|
||||
activeFileTv.tv_sec = fileEpoch;
|
||||
activeFile = file.path();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (not activeFile.has_value()) {
|
||||
return createMostRecentFile(std::nullopt);
|
||||
}
|
||||
|
Reference in New Issue
Block a user