[*] fixed logic in dirlogarchive

todo: get around to improving dirlogarchive
This commit is contained in:
Reece Wilson 2023-07-06 21:26:29 +01:00
parent 72c38548c0
commit 5f9fcce0a1

View File

@ -17,7 +17,7 @@ namespace Aurora::Logging::Sinks
AuList<AuPair<AuString, AuIOFS::Stat>> fileMeta;
AuUInt64 qwSize {};
auto doScan = [&]()
auto doScan = [&](bool bOrder)
{
files.clear();
fileMeta.clear();
@ -33,16 +33,23 @@ namespace Aurora::Logging::Sinks
qwSize += stat.uSize;
}
std::sort(fileMeta.begin(), fileMeta.end(), [](AuPair<AuString, AuIOFS::Stat> a, AuPair<AuString, AuIOFS::Stat> b)
std::sort(fileMeta.begin(), fileMeta.end(), [=](AuPair<AuString, AuIOFS::Stat> a, AuPair<AuString, AuIOFS::Stat> b)
{
return AuGet<1>(a).modifiedNs < AuGet<1>(b).modifiedNs;
if (bOrder)
{
return AuGet<1>(a).modifiedNs < AuGet<1>(b).modifiedNs;
}
else
{
return AuGet<1>(a).modifiedNs > AuGet<1>(b).modifiedNs;
}
});
};
doScan();
if (logger.uMaxLogsOrZeroBeforeCompress)
{
doScan(false);
if (fileMeta.size() > logger.uMaxLogsOrZeroBeforeCompress)
{
for (AuUInt i = logger.uMaxLogsOrZeroBeforeCompress; i < fileMeta.size(); i++)
@ -57,14 +64,14 @@ namespace Aurora::Logging::Sinks
}
}
doScan();
}
}
if (logger.uMaxFileTimeInDeltaMSOrZeroBeforeCompress)
{
doScan(true);
auto qwMaxTime = AuTime::CurrentClockMS() - logger.uMaxFileTimeInDeltaMSOrZeroBeforeCompress;
bool bRescan {};
for (AuUInt i = 0; i < fileMeta.size(); i++)
{
@ -78,20 +85,13 @@ namespace Aurora::Logging::Sinks
{
AuIOFS::Remove(path);
}
bRescan = true;
}
}
if (bRescan)
{
doScan();
}
}
if (logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeCompress)
{
bool bRescan {};
doScan(false);
if (qwSize > logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeCompress)
{
@ -115,33 +115,26 @@ namespace Aurora::Logging::Sinks
{
AuIOFS::Remove(path);
}
bRescan = true;
}
}
if (bRescan)
{
doScan();
}
}
if (logger.uMaxLogsOrZeroBeforeDelete)
{
doScan(false);
if (fileMeta.size() > logger.uMaxLogsOrZeroBeforeDelete)
{
for (AuUInt i = logger.uMaxLogsOrZeroBeforeDelete; i < fileMeta.size(); i++)
{
AuIOFS::Remove(baseLogPath + "/" + fileMeta[i].first);
}
doScan();
}
}
if (logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeDelete)
{
bool bRescan {};
doScan(false);
if (qwSize > logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeDelete)
{
@ -160,20 +153,15 @@ namespace Aurora::Logging::Sinks
if (AuIOFS::Remove(baseLogPath + "/" + fileMeta[i].first))
{
qwSize -= fileMeta[i].second.uSize;
bRescan = true;
}
}
}
if (bRescan)
{
doScan();
}
}
if (logger.uMaxFileTimeInDeltaMSOrZeroBeforeDelete)
{
doScan(true);
auto qwMaxTime = AuTime::CurrentClockMS() - logger.uMaxFileTimeInDeltaMSOrZeroBeforeDelete;
for (AuUInt i = 0; i < fileMeta.size(); i++)