diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 17 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.h | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index d16790b55..13f93eecd 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -75,14 +75,26 @@ VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { | |||
| 75 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 75 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { |
| 76 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); | 76 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 77 | 77 | ||
| 78 | if (auto it = cache.find(path); it != cache.end()) { | ||
| 79 | if (auto file = it->second.lock(); file) { | ||
| 80 | return file; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 78 | auto reference = std::make_unique<FileReference>(); | 84 | auto reference = std::make_unique<FileReference>(); |
| 79 | this->InsertReferenceIntoList(*reference); | 85 | this->InsertReferenceIntoList(*reference); |
| 80 | 86 | ||
| 81 | return std::shared_ptr<RealVfsFile>(new RealVfsFile(*this, std::move(reference), path, perms)); | 87 | auto file = |
| 88 | std::shared_ptr<RealVfsFile>(new RealVfsFile(*this, std::move(reference), path, perms)); | ||
| 89 | cache[path] = file; | ||
| 90 | |||
| 91 | return file; | ||
| 82 | } | 92 | } |
| 83 | 93 | ||
| 84 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 94 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { |
| 85 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); | 95 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 96 | cache.erase(path); | ||
| 97 | |||
| 86 | // Current usages of CreateFile expect to delete the contents of an existing file. | 98 | // Current usages of CreateFile expect to delete the contents of an existing file. |
| 87 | if (FS::IsFile(path)) { | 99 | if (FS::IsFile(path)) { |
| 88 | FS::IOFile temp{path, FS::FileAccessMode::Write, FS::FileType::BinaryFile}; | 100 | FS::IOFile temp{path, FS::FileAccessMode::Write, FS::FileType::BinaryFile}; |
| @@ -111,6 +123,8 @@ VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_ | |||
| 111 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { | 123 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { |
| 112 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); | 124 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); |
| 113 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); | 125 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); |
| 126 | cache.erase(old_path); | ||
| 127 | cache.erase(new_path); | ||
| 114 | if (!FS::RenameFile(old_path, new_path)) { | 128 | if (!FS::RenameFile(old_path, new_path)) { |
| 115 | return nullptr; | 129 | return nullptr; |
| 116 | } | 130 | } |
| @@ -119,6 +133,7 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_ | |||
| 119 | 133 | ||
| 120 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { | 134 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { |
| 121 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); | 135 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 136 | cache.erase(path); | ||
| 122 | return FS::RemoveFile(path); | 137 | return FS::RemoveFile(path); |
| 123 | } | 138 | } |
| 124 | 139 | ||
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index 48dc2698a..d8c900e33 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <map> | ||
| 6 | #include <string_view> | 7 | #include <string_view> |
| 7 | #include "common/intrusive_list.h" | 8 | #include "common/intrusive_list.h" |
| 8 | #include "core/file_sys/mode.h" | 9 | #include "core/file_sys/mode.h" |
| @@ -41,6 +42,7 @@ public: | |||
| 41 | 42 | ||
| 42 | private: | 43 | private: |
| 43 | using ReferenceListType = Common::IntrusiveListBaseTraits<FileReference>::ListType; | 44 | using ReferenceListType = Common::IntrusiveListBaseTraits<FileReference>::ListType; |
| 45 | std::map<std::string, std::weak_ptr<VfsFile>, std::less<>> cache; | ||
| 44 | ReferenceListType open_references; | 46 | ReferenceListType open_references; |
| 45 | ReferenceListType closed_references; | 47 | ReferenceListType closed_references; |
| 46 | size_t num_open_files{}; | 48 | size_t num_open_files{}; |