diff --git a/Source/Core/Core/IOS/FS/FileSystem.cpp b/Source/Core/Core/IOS/FS/FileSystem.cpp index f2beb7d0c8..c6db165002 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.cpp +++ b/Source/Core/Core/IOS/FS/FileSystem.cpp @@ -61,4 +61,29 @@ void FileSystem::Init() if (Delete(0, 0, "/tmp") == ResultCode::Success) CreateDirectory(0, 0, "/tmp", 0, Mode::ReadWrite, Mode::ReadWrite, Mode::ReadWrite); } + +ResultCode FileSystem::CreateFullPath(Uid uid, Gid gid, const std::string& path, + FileAttribute attribute, Mode owner, Mode group, Mode other) +{ + std::string::size_type position = 1; + while (true) + { + position = path.find('/', position); + if (position == std::string::npos) + return ResultCode::Success; + + const std::string subpath = path.substr(0, position); + const Result metadata = GetMetadata(uid, gid, subpath); + if (!metadata && metadata.Error() != ResultCode::NotFound) + return metadata.Error(); + if (metadata && metadata->is_file) + return ResultCode::Invalid; + + const ResultCode result = CreateDirectory(uid, gid, subpath, attribute, owner, group, other); + if (result != ResultCode::Success && result != ResultCode::AlreadyExists) + return result; + + ++position; + } +} } // namespace IOS::HLE::FS diff --git a/Source/Core/Core/IOS/FS/FileSystem.h b/Source/Core/Core/IOS/FS/FileSystem.h index eb14dc6673..42edb14cdf 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.h +++ b/Source/Core/Core/IOS/FS/FileSystem.h @@ -157,6 +157,11 @@ public: FileAttribute attribute, Mode owner_mode, Mode group_mode, Mode other_mode) = 0; + /// Create any parent directories for a path with the specified metadata. + /// Example: "/a/b" to create directory /a; "/a/b/" to create directories /a and /a/b + ResultCode CreateFullPath(Uid caller_uid, Gid caller_gid, const std::string& path, + FileAttribute attribute, Mode ownerm, Mode group, Mode other); + /// Delete a file or directory with the specified path. virtual ResultCode Delete(Uid caller_uid, Gid caller_gid, const std::string& path) = 0; /// Rename a file or directory with the specified path.