Skip to content

Commit

Permalink
IOS/FS: Add CreateFullPath helper
Browse files Browse the repository at this point in the history
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 May 6, 2018
1 parent 8e3cad9 commit 89713c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/Core/Core/IOS/FS/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions Source/Core/Core/IOS/FS/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 89713c5

Please sign in to comment.