summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar Morph2020-12-09 18:07:44 +0800
committerGravatar GitHub2020-12-09 18:07:44 +0800
commit5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a (patch)
tree2537197bb02dfce45dbc55933cabfa06a1b5bc25 /src/common/file_util.cpp
parentMerge pull request #5142 from comex/xx-poll-events (diff)
parentcommon/file_util: Fix and deprecate CreateFullPath, add CreateDirs (diff)
downloadyuzu-5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a.tar.gz
yuzu-5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a.tar.xz
yuzu-5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a.zip
Merge pull request #5174 from ReinUsesLisp/fs-fix
common/file_util: Fix and deprecate CreateFullPath, add CreateDirs
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index d5f6ea2ee..7752c0421 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -98,6 +98,11 @@ bool Delete(const fs::path& path) {
98bool CreateDir(const fs::path& path) { 98bool CreateDir(const fs::path& path) {
99 LOG_TRACE(Common_Filesystem, "directory {}", path.string()); 99 LOG_TRACE(Common_Filesystem, "directory {}", path.string());
100 100
101 if (Exists(path)) {
102 LOG_DEBUG(Common_Filesystem, "path exists {}", path.string());
103 return true;
104 }
105
101 std::error_code ec; 106 std::error_code ec;
102 const bool success = fs::create_directory(path, ec); 107 const bool success = fs::create_directory(path, ec);
103 108
@@ -109,20 +114,41 @@ bool CreateDir(const fs::path& path) {
109 return true; 114 return true;
110} 115}
111 116
112bool CreateFullPath(const fs::path& path) { 117bool CreateDirs(const fs::path& path) {
113 LOG_TRACE(Common_Filesystem, "path {}", path.string()); 118 LOG_TRACE(Common_Filesystem, "path {}", path.string());
114 119
120 if (Exists(path)) {
121 LOG_DEBUG(Common_Filesystem, "path exists {}", path.string());
122 return true;
123 }
124
115 std::error_code ec; 125 std::error_code ec;
116 const bool success = fs::create_directories(path, ec); 126 const bool success = fs::create_directories(path, ec);
117 127
118 if (!success) { 128 if (!success) {
119 LOG_ERROR(Common_Filesystem, "Unable to create full path: {}", ec.message()); 129 LOG_ERROR(Common_Filesystem, "Unable to create directories: {}", ec.message());
120 return false; 130 return false;
121 } 131 }
122 132
123 return true; 133 return true;
124} 134}
125 135
136bool CreateFullPath(const fs::path& path) {
137 LOG_TRACE(Common_Filesystem, "path {}", path);
138
139 // Removes trailing slashes and turns any '\' into '/'
140 const auto new_path = SanitizePath(path.string(), DirectorySeparator::ForwardSlash);
141
142 if (new_path.rfind('.') == std::string::npos) {
143 // The path is a directory
144 return CreateDirs(new_path);
145 } else {
146 // The path is a file
147 // Creates directory preceding the last '/'
148 return CreateDirs(new_path.substr(0, new_path.rfind('/')));
149 }
150}
151
126bool Rename(const fs::path& src, const fs::path& dst) { 152bool Rename(const fs::path& src, const fs::path& dst) {
127 LOG_TRACE(Common_Filesystem, "{} --> {}", src.string(), dst.string()); 153 LOG_TRACE(Common_Filesystem, "{} --> {}", src.string(), dst.string());
128 154