IOS/FS: Actually implement SetMetadata

This commit is contained in:
Léo Lam 2019-12-29 14:01:39 +01:00
parent e4dd582d1d
commit 142b7e048b
1 changed files with 21 additions and 1 deletions

View File

@ -610,10 +610,30 @@ Result<Metadata> HostFileSystem::GetMetadata(Uid uid, Gid gid, const std::string
}
ResultCode HostFileSystem::SetMetadata(Uid caller_uid, const std::string& path, Uid uid, Gid gid,
FileAttribute, Modes)
FileAttribute attr, Modes modes)
{
if (!IsValidPath(path))
return ResultCode::Invalid;
FstEntry* entry = GetFstEntryForPath(path);
if (!entry)
return ResultCode::NotFound;
if (caller_uid != 0 && caller_uid != entry->data.uid)
return ResultCode::AccessDenied;
if (caller_uid != 0 && uid != entry->data.uid)
return ResultCode::AccessDenied;
const bool is_empty = File::GetSize(BuildFilename(path)) == 0;
if (entry->data.uid != uid && entry->data.is_file && !is_empty)
return ResultCode::FileNotEmpty;
entry->data.gid = gid;
entry->data.uid = uid;
entry->data.attribute = attr;
entry->data.modes = modes;
SaveFst();
return ResultCode::Success;
}