From 04c9004e05facdf83ea0a351a215f761f51b9c43 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 13 Dec 2022 01:08:13 -0700 Subject: [PATCH] erpt: fix multiple issues with automatic report cleanup (thanks @yellows8) * Setting retrieval was performed before the call that used the setting. * Call to detect number of files passed incomplete path and was guaranteed to fail. * Call to delete reports passed incomplete path and was guaranteed to do nothing. --- .../include/stratosphere/erpt/srv/erpt_srv_types.hpp | 1 + .../source/erpt/srv/erpt_srv_main.cpp | 4 ++-- stratosphere/erpt/source/erpt_main.cpp | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_types.hpp b/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_types.hpp index dcfd85c9c..2b1ec9830 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_types.hpp @@ -21,6 +21,7 @@ namespace ams::erpt::srv { constexpr inline const char ReportOnSdStoragePath[] = "ersd"; + constexpr inline const char ReportOnSdStorageRootDirectoryPath[] = "ersd:/"; constexpr inline const char ReportStoragePath[] = "save"; constexpr inline const char JournalFileName[] = "save:/journal"; diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp index affc0b453..c3bb485ff 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp @@ -88,7 +88,7 @@ namespace ams::erpt::srv { s64 report_count = MinimumReportCountForCleanup; fs::DirectoryHandle dir; - if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(dir), ReportOnSdStoragePath, fs::OpenDirectoryMode_All))) { + if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(dir), ReportOnSdStorageRootDirectoryPath, fs::OpenDirectoryMode_All))) { ON_SCOPE_EXIT { fs::CloseDirectory(dir); }; if (R_FAILED(fs::GetDirectoryEntryCount(std::addressof(report_count), dir))) { @@ -97,7 +97,7 @@ namespace ams::erpt::srv { } if (report_count >= MinimumReportCountForCleanup) { - fs::CleanDirectoryRecursively(ReportOnSdStoragePath); + fs::CleanDirectoryRecursively(ReportOnSdStorageRootDirectoryPath); } } diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 91a0e34bf..d95a0ae60 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -78,12 +78,6 @@ namespace ams { os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(erpt, Main)); AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(erpt, Main)); - /* Set the memory heap for erpt::srv namespace. */ - R_ABORT_UNLESS(erpt::srv::Initialize(erpt::g_memory_heap, erpt::MemoryHeapSize)); - - /* Atmosphere always wants to redirect new reports to the SD card, to prevent them from being logged. */ - erpt::srv::SetRedirectNewReportsToSdCard(true); - /* Decide whether or not to clean up reports periodically. */ { u8 disable_report_cleanup = 0; @@ -94,6 +88,12 @@ namespace ams { } } + /* Set the memory heap for erpt::srv namespace, perform other service init/etc. */ + R_ABORT_UNLESS(erpt::srv::Initialize(erpt::g_memory_heap, erpt::MemoryHeapSize)); + + /* Atmosphere always wants to redirect new reports to the SD card, to prevent them from being logged. */ + erpt::srv::SetRedirectNewReportsToSdCard(true); + /* Configure the OS version. */ { settings::system::FirmwareVersion firmware_version = {};