diff options
| author | 2018-07-23 22:40:35 -0400 | |
|---|---|---|
| committer | 2018-07-23 19:40:35 -0700 | |
| commit | 59cb258409c5cbd6cdc9cc6a6f8e858603924a2b (patch) | |
| tree | c024d285fe63daae9d73ef07800349a065768672 /src/core/hle | |
| parent | Merge pull request #787 from bunnei/tlds (diff) | |
| download | yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.gz yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.xz yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.zip | |
VFS Regression and Accuracy Fixes (#776)
* Regression and Mode Fixes
* Review Fixes
* string_view correction
* Add operator& for FileSys::Mode
* Return std::string from SanitizePath
* Farming Simulator Fix
* Use != With mode operator&
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index dbfe06cbc..fdd2fda18 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -24,7 +24,8 @@ namespace Service::FileSystem { | |||
| 24 | constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; | 24 | constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; |
| 25 | 25 | ||
| 26 | static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, | 26 | static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, |
| 27 | std::string_view dir_name) { | 27 | std::string_view dir_name_) { |
| 28 | std::string dir_name(FileUtil::SanitizePath(dir_name_)); | ||
| 28 | if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\") | 29 | if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\") |
| 29 | return base; | 30 | return base; |
| 30 | 31 | ||
| @@ -38,7 +39,8 @@ std::string VfsDirectoryServiceWrapper::GetName() const { | |||
| 38 | return backing->GetName(); | 39 | return backing->GetName(); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 size) const { | 42 | ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const { |
| 43 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 42 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 44 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 43 | auto file = dir->CreateFile(FileUtil::GetFilename(path)); | 45 | auto file = dir->CreateFile(FileUtil::GetFilename(path)); |
| 44 | if (file == nullptr) { | 46 | if (file == nullptr) { |
| @@ -52,7 +54,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 s | |||
| 52 | return RESULT_SUCCESS; | 54 | return RESULT_SUCCESS; |
| 53 | } | 55 | } |
| 54 | 56 | ||
| 55 | ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const { | 57 | ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const { |
| 58 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 56 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 59 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 57 | if (path == "/" || path == "\\") { | 60 | if (path == "/" || path == "\\") { |
| 58 | // TODO(DarkLordZach): Why do games call this and what should it do? Works as is but... | 61 | // TODO(DarkLordZach): Why do games call this and what should it do? Works as is but... |
| @@ -60,14 +63,15 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const | |||
| 60 | } | 63 | } |
| 61 | if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) | 64 | if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) |
| 62 | return FileSys::ERROR_PATH_NOT_FOUND; | 65 | return FileSys::ERROR_PATH_NOT_FOUND; |
| 63 | if (!backing->DeleteFile(FileUtil::GetFilename(path))) { | 66 | if (!dir->DeleteFile(FileUtil::GetFilename(path))) { |
| 64 | // TODO(DarkLordZach): Find a better error code for this | 67 | // TODO(DarkLordZach): Find a better error code for this |
| 65 | return ResultCode(-1); | 68 | return ResultCode(-1); |
| 66 | } | 69 | } |
| 67 | return RESULT_SUCCESS; | 70 | return RESULT_SUCCESS; |
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) const { | 73 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { |
| 74 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 71 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 75 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 72 | if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty()) | 76 | if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty()) |
| 73 | dir = backing; | 77 | dir = backing; |
| @@ -79,7 +83,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) | |||
| 79 | return RESULT_SUCCESS; | 83 | return RESULT_SUCCESS; |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) const { | 86 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const { |
| 87 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 83 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 88 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 84 | if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { | 89 | if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { |
| 85 | // TODO(DarkLordZach): Find a better error code for this | 90 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -88,7 +93,8 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) | |||
| 88 | return RESULT_SUCCESS; | 93 | return RESULT_SUCCESS; |
| 89 | } | 94 | } |
| 90 | 95 | ||
| 91 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path) const { | 96 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const { |
| 97 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 92 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 98 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 93 | if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { | 99 | if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { |
| 94 | // TODO(DarkLordZach): Find a better error code for this | 100 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -97,8 +103,10 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str | |||
| 97 | return RESULT_SUCCESS; | 103 | return RESULT_SUCCESS; |
| 98 | } | 104 | } |
| 99 | 105 | ||
| 100 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, | 106 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_, |
| 101 | const std::string& dest_path) const { | 107 | const std::string& dest_path_) const { |
| 108 | std::string src_path(FileUtil::SanitizePath(src_path_)); | ||
| 109 | std::string dest_path(FileUtil::SanitizePath(dest_path_)); | ||
| 102 | auto src = backing->GetFileRelative(src_path); | 110 | auto src = backing->GetFileRelative(src_path); |
| 103 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { | 111 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { |
| 104 | // Use more-optimized vfs implementation rename. | 112 | // Use more-optimized vfs implementation rename. |
| @@ -130,8 +138,10 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, | |||
| 130 | return RESULT_SUCCESS; | 138 | return RESULT_SUCCESS; |
| 131 | } | 139 | } |
| 132 | 140 | ||
| 133 | ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path, | 141 | ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_, |
| 134 | const std::string& dest_path) const { | 142 | const std::string& dest_path_) const { |
| 143 | std::string src_path(FileUtil::SanitizePath(src_path_)); | ||
| 144 | std::string dest_path(FileUtil::SanitizePath(dest_path_)); | ||
| 135 | auto src = GetDirectoryRelativeWrapped(backing, src_path); | 145 | auto src = GetDirectoryRelativeWrapped(backing, src_path); |
| 136 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { | 146 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { |
| 137 | // Use more-optimized vfs implementation rename. | 147 | // Use more-optimized vfs implementation rename. |
| @@ -154,8 +164,9 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa | |||
| 154 | return ResultCode(-1); | 164 | return ResultCode(-1); |
| 155 | } | 165 | } |
| 156 | 166 | ||
| 157 | ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path, | 167 | ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, |
| 158 | FileSys::Mode mode) const { | 168 | FileSys::Mode mode) const { |
| 169 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 159 | auto npath = path; | 170 | auto npath = path; |
| 160 | while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) | 171 | while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) |
| 161 | npath = npath.substr(1); | 172 | npath = npath.substr(1); |
| @@ -171,7 +182,8 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std:: | |||
| 171 | return MakeResult<FileSys::VirtualFile>(file); | 182 | return MakeResult<FileSys::VirtualFile>(file); |
| 172 | } | 183 | } |
| 173 | 184 | ||
| 174 | ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path) { | 185 | ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { |
| 186 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 175 | auto dir = GetDirectoryRelativeWrapped(backing, path); | 187 | auto dir = GetDirectoryRelativeWrapped(backing, path); |
| 176 | if (dir == nullptr) { | 188 | if (dir == nullptr) { |
| 177 | // TODO(DarkLordZach): Find a better error code for this | 189 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -188,7 +200,8 @@ u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const { | |||
| 188 | } | 200 | } |
| 189 | 201 | ||
| 190 | ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( | 202 | ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( |
| 191 | const std::string& path) const { | 203 | const std::string& path_) const { |
| 204 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 192 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 205 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 193 | if (dir == nullptr) | 206 | if (dir == nullptr) |
| 194 | return FileSys::ERROR_PATH_NOT_FOUND; | 207 | return FileSys::ERROR_PATH_NOT_FOUND; |
| @@ -272,9 +285,9 @@ void RegisterFileSystems() { | |||
| 272 | sdmc_factory = nullptr; | 285 | sdmc_factory = nullptr; |
| 273 | 286 | ||
| 274 | auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( | 287 | auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( |
| 275 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::Write); | 288 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::ReadWrite); |
| 276 | auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( | 289 | auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( |
| 277 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::Write); | 290 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::ReadWrite); |
| 278 | 291 | ||
| 279 | auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); | 292 | auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); |
| 280 | save_data_factory = std::move(savedata); | 293 | save_data_factory = std::move(savedata); |