From 9d9f210ddb9b3dbac2f632c881a42b08de708d16 Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:17:09 +0300 Subject: [PATCH] sys_fs: Debug validation layer for ENOTDIR detector --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 61f8ab45f..e817b602c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -149,24 +149,39 @@ bool verify_mself(const fs::file& mself_file) // TODO: May not be thread-safe (or even, process-safe) bool has_non_directory_components(std::string_view path) { - std::string path0{path}; + std::string sub_path{path}; + + fs::stat_t stat{}; while (true) { - const std::string sub_path = fs::get_parent_dir(path0); + std::string_view path_sv = fs::get_parent_dir_view(sub_path); + const usz sv_size = path_sv.size(); - if (sub_path.size() >= path0.size()) + if (sv_size >= sub_path.size()) { + sys_fs.error("has_non_directory_components() did not find a directory! (path=%s, sub_path=%s)", path, sub_path); break; } - fs::stat_t stat{}; + // Trim child path tail + path_sv = {}; + sub_path.resize(sv_size); + if (fs::get_stat(sub_path, stat)) { + if (!stat.is_directory) + { + sys_fs.error("has_non_directory_components() returned an affirmative (sub_path=%s)", sub_path); + } + return !stat.is_directory; } - path0 = std::move(sub_path); + if (fs::g_tls_error != fs::error::noent) + { + fmt::throw_exception("sys_fs: fs::get_stat() failed with error '%s' (sub_path=%s)", fs::g_tls_error, sub_path); + } } return false;