Permalink
Browse files

IOS/FS: Add CreateFullPath helper

Analogous to File::CreateFullPath, but for the Wii filesystem so this
ensures that directories and files receive proper attributes.

(This function is technically not part of the FS sysmodule but it's in
an internal FS library that is reused in several IOS sysmodules.)
  • Loading branch information...
leoetlino committed Mar 7, 2018
1 parent 8e3cad9 commit 89713c588955a8d9a687e4b0351e0684ed51e241
Showing with 30 additions and 0 deletions.
  1. +25 −0 Source/Core/Core/IOS/FS/FileSystem.cpp
  2. +5 −0 Source/Core/Core/IOS/FS/FileSystem.h
@@ -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> 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
@@ -157,6 +157,11 @@ class FileSystem
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.

0 comments on commit 89713c5

Please sign in to comment.