[fs] moved temp folder cleanup upstream (per-application level) to avoid per-program retrigger (#4375)

- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions).
- [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md)
- [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability.

-------------------

This issue was observed in MGS Master Collection Volume II, MGS4: Guns of the Patriots, Chapter 4: Shadow Moses

That title is a bundle, and that specific chapter is a program (MGS 1st stage), launched by a program (MGS4), launched by an application (main title bundle).

Upon decoding guest panic message, it was exposed that an abort was triggered after trying to create a save in nand/temp/gclvar.bak file.
Further instrumentation exposed the error on that file's path, caused from a previous deletion of that folder.
In the same session that folder had been already cleaned and created successfully, which evidences an undesired re-cleaning of the temp structure.

The issue was the fact that the MGS4 to MGS transition also calls EnsureSaveData>...>SaveDataFactory creator, and that was destroying the previous created temp structure. After that stage, the return from MSG to MSG4 was causing the same issue again.

By moving the deletion to the guest application level, the factory creation was called only once, as it should be, and the issue is gone.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4375
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
xbzk
2026-09-10 22:30:07 +02:00
committed by crueter
parent 00a1c392e7
commit f3af5d0c25
4 changed files with 14 additions and 5 deletions
+4
View File
@@ -312,6 +312,10 @@ struct System::Impl {
}
SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, Service::AM::FrontendAppletParameters& params) {
if (params.launch_type == Service::AM::LaunchType::FrontendInitiated) {
fs_controller.InitTempStorage();
}
InitializeKernel(system);
if (params.applet_type == Service::AM::AppletType::Application) {
+1 -5
View File
@@ -57,11 +57,7 @@ std::string GetFutureSaveDataPath(SaveDataSpaceId space_id, SaveDataType type, u
SaveDataFactory::SaveDataFactory(Core::System& system_, ProgramId program_id_,
VirtualDir save_directory_)
: system{system_}, program_id{program_id_}, dir{std::move(save_directory_)} {
// Delete all temporary storages
// On hardware, it is expected that temporary storage be empty at first use.
dir->DeleteSubdirectoryRecursive("temp");
}
: system{system_}, program_id{program_id_}, dir{std::move(save_directory_)} {}
SaveDataFactory::~SaveDataFactory() = default;
@@ -787,6 +787,13 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
}
}
void FileSystemController::InitTempStorage() {
const auto save_directory = system.GetFilesystem()->OpenDirectory(Common::FS::GetEdenPathString(Common::FS::EdenPath::SaveDir), FileSys::OpenMode::ReadWrite);
if (save_directory != nullptr) {
save_directory->DeleteSubdirectoryRecursive("temp");
}
}
void FileSystemController::Reset() {
std::scoped_lock lk{registration_lock};
registrations.clear();
@@ -127,6 +127,8 @@ public:
// above is called.
void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite = true);
void InitTempStorage();
void Reset();
private: