Skip to content

Commit 069bdcd

Browse files
committed
Fixup: Log cleanup
1 parent 9c4edc2 commit 069bdcd

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

UI/obs-app.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,9 +1650,8 @@ static uint64_t convert_log_name(bool has_prefix, const char *name)
16501650
static void delete_oldest_file(bool has_prefix, const char *location)
16511651
{
16521652
BPtr<char> logDir(GetConfigPathPtr(location));
1653-
string oldestLog;
1654-
uint64_t oldest_ts = (uint64_t)-1;
16551653
struct os_dirent *entry;
1654+
map<int, string> list;
16561655

16571656
unsigned int maxLogs = (unsigned int)config_get_uint(
16581657
App()->GlobalConfig(), "General", "MaxLogs");
@@ -1668,12 +1667,9 @@ static void delete_oldest_file(bool has_prefix, const char *location)
16681667
uint64_t ts =
16691668
convert_log_name(has_prefix, entry->d_name);
16701669

1671-
if (ts) {
1672-
if (ts < oldest_ts) {
1673-
oldestLog = entry->d_name;
1674-
oldest_ts = ts;
1675-
}
16761670

1671+
if (ts) {
1672+
list[ts] = entry->d_name;
16771673
count++;
16781674
}
16791675
}
@@ -1682,9 +1678,14 @@ static void delete_oldest_file(bool has_prefix, const char *location)
16821678

16831679
if (count > maxLogs) {
16841680
stringstream delPath;
1681+
const auto end = list.size() - maxLogs;
1682+
count = 0;
1683+
for(auto const & item : list) {
1684+
if (count++ >= end) break;
16851685

1686-
delPath << logDir << "/" << oldestLog;
1687-
os_unlink(delPath.str().c_str());
1686+
delPath << logDir << "/" << item.second;
1687+
os_unlink(delPath.str().c_str());
1688+
}
16881689
}
16891690
}
16901691
}

0 commit comments

Comments
 (0)