Merge pull request #6974 from ogniK5377/fs-recursive-createdir

FS: Recursively create directories for CreateDirectory
This commit is contained in:
Morph 2021-09-12 12:02:39 -04:00 committed by GitHub
commit f0f416e85c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,15 +97,20 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) cons
ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
std::string path(Common::FS::SanitizePath(path_)); std::string path(Common::FS::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path)); const auto components = Common::FS::SplitPathComponents(path);
if (dir == nullptr || Common::FS::GetFilename(Common::FS::GetParentPath(path)).empty()) { std::string relative_path;
dir = backing; for (const auto& component : components) {
// Skip empty path components
if (component.empty()) {
continue;
} }
auto new_dir = dir->CreateSubdirectory(Common::FS::GetFilename(path)); relative_path = Common::FS::SanitizePath(relative_path + '/' + component);
auto new_dir = backing->CreateSubdirectory(relative_path);
if (new_dir == nullptr) { if (new_dir == nullptr) {
// TODO(DarkLordZach): Find a better error code for this // TODO(DarkLordZach): Find a better error code for this
return ResultUnknown; return ResultUnknown;
} }
}
return ResultSuccess; return ResultSuccess;
} }