mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-28 05:52:39 +02:00
erpt: add automatic report cleanup mechanism on boot (closes #1795)
This commit is contained in:
parent
a2e891d5e8
commit
c5ae3c2449
@ -27,6 +27,7 @@ namespace ams::erpt::srv {
|
|||||||
|
|
||||||
/* Atmosphere extension. */
|
/* Atmosphere extension. */
|
||||||
Result SetRedirectNewReportsToSdCard(bool redirect);
|
Result SetRedirectNewReportsToSdCard(bool redirect);
|
||||||
|
Result SetEnabledAutomaticReportCleanup(bool redirect);
|
||||||
|
|
||||||
void Wait();
|
void Wait();
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ namespace ams::erpt::srv {
|
|||||||
constexpr s64 SystemSaveDataSize = 11_MB;
|
constexpr s64 SystemSaveDataSize = 11_MB;
|
||||||
constexpr s64 SystemSaveDataJournalSize = 2720_KB;
|
constexpr s64 SystemSaveDataJournalSize = 2720_KB;
|
||||||
|
|
||||||
|
constinit bool g_automatic_report_cleanup_enabled = true;
|
||||||
|
|
||||||
Result ExtendSystemSaveData() {
|
Result ExtendSystemSaveData() {
|
||||||
s64 cur_journal_size;
|
s64 cur_journal_size;
|
||||||
s64 cur_savedata_size;
|
s64 cur_savedata_size;
|
||||||
@ -81,6 +83,24 @@ namespace ams::erpt::srv {
|
|||||||
|
|
||||||
R_ABORT_UNLESS(fs::MountSdCardErrorReportDirectoryForAtmosphere(ReportOnSdStoragePath));
|
R_ABORT_UNLESS(fs::MountSdCardErrorReportDirectoryForAtmosphere(ReportOnSdStoragePath));
|
||||||
|
|
||||||
|
if (g_automatic_report_cleanup_enabled) {
|
||||||
|
constexpr s64 MinimumReportCountForCleanup = 1000;
|
||||||
|
s64 report_count = MinimumReportCountForCleanup;
|
||||||
|
|
||||||
|
fs::DirectoryHandle dir;
|
||||||
|
if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(dir), ReportOnSdStoragePath, fs::OpenDirectoryMode_All))) {
|
||||||
|
ON_SCOPE_EXIT { fs::CloseDirectory(dir); };
|
||||||
|
|
||||||
|
if (R_FAILED(fs::GetDirectoryEntryCount(std::addressof(report_count), dir))) {
|
||||||
|
report_count = MinimumReportCountForCleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (report_count >= MinimumReportCountForCleanup) {
|
||||||
|
fs::CleanDirectoryRecursively(ReportOnSdStoragePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
R_ABORT_UNLESS(MountSystemSaveData());
|
R_ABORT_UNLESS(MountSystemSaveData());
|
||||||
|
|
||||||
g_sf_allocator.Attach(g_heap_handle);
|
g_sf_allocator.Attach(g_heap_handle);
|
||||||
@ -137,6 +157,11 @@ namespace ams::erpt::srv {
|
|||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result SetEnabledAutomaticReportCleanup(bool en) {
|
||||||
|
g_automatic_report_cleanup_enabled = en;
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
void Wait() {
|
void Wait() {
|
||||||
/* Get the update event. */
|
/* Get the update event. */
|
||||||
os::Event *event = GetForcedShutdownUpdateEvent();
|
os::Event *event = GetForcedShutdownUpdateEvent();
|
||||||
|
Loading…
Reference in New Issue
Block a user