summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-07-23 22:40:35 -0400
committerGravatar bunnei2018-07-23 19:40:35 -0700
commit59cb258409c5cbd6cdc9cc6a6f8e858603924a2b (patch)
treec024d285fe63daae9d73ef07800349a065768672 /src/core/file_sys
parentMerge pull request #787 from bunnei/tlds (diff)
downloadyuzu-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.h6
-rw-r--r--src/core/file_sys/vfs_real.cpp47
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 {
11enum class Mode : u32 { 11enum 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
19inline 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
14namespace FileSys { 14namespace FileSys {
15 15
16static std::string PermissionsToCharArray(Mode perms) { 16static 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
32RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) 39RealVfsFile::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
55bool RealVfsFile::IsWritable() const { 62bool RealVfsFile::IsWritable() const {
56 return perms == Mode::Append || perms == Mode::Write; 63 return (perms & Mode::WriteAppend) != 0;
57} 64}
58 65
59bool RealVfsFile::IsReadable() const { 66bool RealVfsFile::IsReadable() const {
60 return perms == Mode::Read || perms == Mode::Write; 67 return (perms & Mode::ReadWrite) != 0;
61} 68}
62 69
63size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { 70size_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
122bool RealVfsDirectory::IsWritable() const { 129bool RealVfsDirectory::IsWritable() const {
123 return perms == Mode::Write || perms == Mode::Append; 130 return (perms & Mode::WriteAppend) != 0;
124} 131}
125 132
126bool RealVfsDirectory::IsReadable() const { 133bool RealVfsDirectory::IsReadable() const {
127 return perms == Mode::Read || perms == Mode::Write; 134 return (perms & Mode::ReadWrite) != 0;
128} 135}
129 136
130std::string RealVfsDirectory::GetName() const { 137std::string RealVfsDirectory::GetName() const {