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/file_sys | |
| 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/file_sys')
| -rw-r--r-- | src/core/file_sys/mode.h | 6 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 47 |
2 files changed, 33 insertions, 20 deletions
diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h index b4363152a..c95205668 100644 --- a/src/core/file_sys/mode.h +++ b/src/core/file_sys/mode.h | |||
| @@ -11,7 +11,13 @@ namespace FileSys { | |||
| 11 | enum class Mode : u32 { | 11 | enum class Mode : u32 { |
| 12 | Read = 1, | 12 | Read = 1, |
| 13 | Write = 2, | 13 | Write = 2, |
| 14 | ReadWrite = 3, | ||
| 14 | Append = 4, | 15 | Append = 4, |
| 16 | WriteAppend = 6, | ||
| 15 | }; | 17 | }; |
| 16 | 18 | ||
| 19 | inline u32 operator&(Mode lhs, Mode rhs) { | ||
| 20 | return static_cast<u32>(lhs) & static_cast<u32>(rhs); | ||
| 21 | } | ||
| 22 | |||
| 17 | } // namespace FileSys | 23 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 095fec77e..9ce2e1efa 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -13,24 +13,31 @@ | |||
| 13 | 13 | ||
| 14 | namespace FileSys { | 14 | namespace FileSys { |
| 15 | 15 | ||
| 16 | static std::string PermissionsToCharArray(Mode perms) { | 16 | static std::string ModeFlagsToString(Mode mode) { |
| 17 | std::string out; | 17 | std::string mode_str; |
| 18 | switch (perms) { | 18 | |
| 19 | case Mode::Read: | 19 | // Calculate the correct open mode for the file. |
| 20 | out += "r"; | 20 | if (mode & Mode::Read && mode & Mode::Write) { |
| 21 | break; | 21 | if (mode & Mode::Append) |
| 22 | case Mode::Write: | 22 | mode_str = "a+"; |
| 23 | out += "r+"; | 23 | else |
| 24 | break; | 24 | mode_str = "r+"; |
| 25 | case Mode::Append: | 25 | } else { |
| 26 | out += "a"; | 26 | if (mode & Mode::Read) |
| 27 | break; | 27 | mode_str = "r"; |
| 28 | else if (mode & Mode::Append) | ||
| 29 | mode_str = "a"; | ||
| 30 | else if (mode & Mode::Write) | ||
| 31 | mode_str = "w"; | ||
| 28 | } | 32 | } |
| 29 | return out + "b"; | 33 | |
| 34 | mode_str += "b"; | ||
| 35 | |||
| 36 | return mode_str; | ||
| 30 | } | 37 | } |
| 31 | 38 | ||
| 32 | RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) | 39 | RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) |
| 33 | : backing(path_, PermissionsToCharArray(perms_).c_str()), path(path_), | 40 | : backing(path_, ModeFlagsToString(perms_).c_str()), path(path_), |
| 34 | parent_path(FileUtil::GetParentPath(path_)), | 41 | parent_path(FileUtil::GetParentPath(path_)), |
| 35 | path_components(FileUtil::SplitPathComponents(path_)), | 42 | path_components(FileUtil::SplitPathComponents(path_)), |
| 36 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | 43 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), |
| @@ -53,11 +60,11 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const { | |||
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | bool RealVfsFile::IsWritable() const { | 62 | bool RealVfsFile::IsWritable() const { |
| 56 | return perms == Mode::Append || perms == Mode::Write; | 63 | return (perms & Mode::WriteAppend) != 0; |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | bool RealVfsFile::IsReadable() const { | 66 | bool RealVfsFile::IsReadable() const { |
| 60 | return perms == Mode::Read || perms == Mode::Write; | 67 | return (perms & Mode::ReadWrite) != 0; |
| 61 | } | 68 | } |
| 62 | 69 | ||
| 63 | size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { | 70 | size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { |
| @@ -79,7 +86,7 @@ bool RealVfsFile::Rename(std::string_view name) { | |||
| 79 | path = (parent_path + DIR_SEP).append(name); | 86 | path = (parent_path + DIR_SEP).append(name); |
| 80 | path_components = parent_components; | 87 | path_components = parent_components; |
| 81 | path_components.push_back(std::move(name_str)); | 88 | path_components.push_back(std::move(name_str)); |
| 82 | backing = FileUtil::IOFile(path, PermissionsToCharArray(perms).c_str()); | 89 | backing = FileUtil::IOFile(path, ModeFlagsToString(perms).c_str()); |
| 83 | 90 | ||
| 84 | return out; | 91 | return out; |
| 85 | } | 92 | } |
| @@ -93,7 +100,7 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_) | |||
| 93 | path_components(FileUtil::SplitPathComponents(path)), | 100 | path_components(FileUtil::SplitPathComponents(path)), |
| 94 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | 101 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), |
| 95 | perms(perms_) { | 102 | perms(perms_) { |
| 96 | if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append)) | 103 | if (!FileUtil::Exists(path) && perms & Mode::WriteAppend) |
| 97 | FileUtil::CreateDir(path); | 104 | FileUtil::CreateDir(path); |
| 98 | 105 | ||
| 99 | if (perms == Mode::Append) | 106 | if (perms == Mode::Append) |
| @@ -120,11 +127,11 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() | |||
| 120 | } | 127 | } |
| 121 | 128 | ||
| 122 | bool RealVfsDirectory::IsWritable() const { | 129 | bool RealVfsDirectory::IsWritable() const { |
| 123 | return perms == Mode::Write || perms == Mode::Append; | 130 | return (perms & Mode::WriteAppend) != 0; |
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | bool RealVfsDirectory::IsReadable() const { | 133 | bool RealVfsDirectory::IsReadable() const { |
| 127 | return perms == Mode::Read || perms == Mode::Write; | 134 | return (perms & Mode::ReadWrite) != 0; |
| 128 | } | 135 | } |
| 129 | 136 | ||
| 130 | std::string RealVfsDirectory::GetName() const { | 137 | std::string RealVfsDirectory::GetName() const { |