diff --git a/src/xenia/vfs/devices/host_path_entry.cc b/src/xenia/vfs/devices/host_path_entry.cc index 8d1025d4d..b260e6b64 100644 --- a/src/xenia/vfs/devices/host_path_entry.cc +++ b/src/xenia/vfs/devices/host_path_entry.cc @@ -103,9 +103,10 @@ bool HostPathEntry::DeleteEntryInternal(Entry* entry) { auto removed = std::filesystem::remove_all(full_path, ec); return removed >= 1 && removed != static_cast(-1); } else { - // Delete file. + // Delete file only if it exists. return !std::filesystem::is_directory(full_path) && - std::filesystem::remove(full_path, ec); + (!std::filesystem::exists(full_path) || + std::filesystem::remove(full_path, ec)); } } diff --git a/src/xenia/vfs/devices/host_path_entry.h b/src/xenia/vfs/devices/host_path_entry.h index bb12b7a14..0a1b3e80d 100644 --- a/src/xenia/vfs/devices/host_path_entry.h +++ b/src/xenia/vfs/devices/host_path_entry.h @@ -30,7 +30,7 @@ class HostPathEntry : public Entry { const std::filesystem::path& full_path, xe::filesystem::FileInfo file_info); - const std::filesystem::path& host_path() { return host_path_; } + const std::filesystem::path& host_path() const { return host_path_; } X_STATUS Open(uint32_t desired_access, File** out_file) override; diff --git a/src/xenia/vfs/virtual_file_system.cc b/src/xenia/vfs/virtual_file_system.cc index ba25260a6..abc520f4a 100644 --- a/src/xenia/vfs/virtual_file_system.cc +++ b/src/xenia/vfs/virtual_file_system.cc @@ -11,6 +11,7 @@ #include "xenia/kernel/xam/content_manager.h" #include "xenia/vfs/devices/stfs_container_device.h" +#include "devices/host_path_entry.h" #include "xenia/base/literals.h" #include "xenia/base/logging.h" #include "xenia/base/string.h" @@ -221,6 +222,22 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry, if (entry->attributes() & kFileAttributeDirectory && is_non_directory) { return X_STATUS_FILE_IS_A_DIRECTORY; } + + // If the entry does not exist on the host then remove the cached entry + if (parent_entry) { + const xe::vfs::HostPathEntry* host_Path = + dynamic_cast(parent_entry); + + if (host_Path) { + auto const file_path = host_Path->host_path() / entry->name(); + + if (!std::filesystem::exists(file_path)) { + // Remove cached entry + entry->Delete(); + entry = nullptr; + } + } + } } // Check if exists (if we need it to), or that it doesn't (if it shouldn't).