mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 07:21:14 +01:00
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.)
This commit is contained in:
parent
8e3cad948c
commit
89713c5889
@ -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 @@ 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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user