mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 18:58:56 +00:00
LibCore: Add Directory::chown() API and use it in Core::Account
Since we already have the directory open, let's have an API to fchown() the underlying file descriptor instead of forcing clients to do another path lookup.
This commit is contained in:
parent
3f14582b85
commit
c1af2f28e3
Notes:
sideshowbarker
2024-07-17 08:13:43 +09:00
Author: https://github.com/awesomekling
Commit: c1af2f28e3
3 changed files with 12 additions and 2 deletions
|
@ -152,8 +152,8 @@ bool Account::authenticate(SecretString const& password) const
|
|||
ErrorOr<void> Account::create_user_temporary_directory_if_needed() const
|
||||
{
|
||||
auto const temporary_directory = String::formatted("/tmp/user/{}", m_uid);
|
||||
TRY(Core::Directory::create(temporary_directory, Core::Directory::CreateDirectories::Yes));
|
||||
TRY(Core::System::chown(temporary_directory, m_uid, m_gid));
|
||||
auto directory = TRY(Core::Directory::create(temporary_directory, Core::Directory::CreateDirectories::Yes));
|
||||
TRY(directory.chown(m_uid, m_gid));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,14 @@ Directory::~Directory()
|
|||
MUST(System::close(m_directory_fd));
|
||||
}
|
||||
|
||||
ErrorOr<void> Directory::chown(uid_t uid, gid_t gid)
|
||||
{
|
||||
if (m_directory_fd == -1)
|
||||
return Error::from_syscall("fchown"sv, -EBADF);
|
||||
TRY(Core::System::fchown(m_directory_fd, uid, gid));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<bool> Directory::is_valid_directory(int fd)
|
||||
{
|
||||
auto stat = TRY(System::fstat(fd));
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
|
||||
ErrorOr<LexicalPath> path() const;
|
||||
|
||||
ErrorOr<void> chown(uid_t, gid_t);
|
||||
|
||||
static ErrorOr<bool> is_valid_directory(int fd);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue