summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/Directory.h
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-02 16:37:46 +0000
committerAndreas Kling <kling@serenityos.org>2023-03-05 20:23:42 +0100
commit7864898f52f52f4db82f06747ac817247b850b2d (patch)
tree064a88115a745d7a6d8e3f4dfd750889612e4b46 /Userland/Libraries/LibCore/Directory.h
parent774f328783db31a02eba76d7c55d53a0b41b1508 (diff)
downloadserenity-7864898f52f52f4db82f06747ac817247b850b2d.zip
LibCore: Ensure that Directory always has a path
`Directory::path()` returning `ErrorOr` makes it awkward to use, and all current users create a Directory with a path. If we find we need pathless directories later, we can come up with a clever solution then. :^)
Diffstat (limited to 'Userland/Libraries/LibCore/Directory.h')
-rw-r--r--Userland/Libraries/LibCore/Directory.h13
1 files changed, 5 insertions, 8 deletions
diff --git a/Userland/Libraries/LibCore/Directory.h b/Userland/Libraries/LibCore/Directory.h
index 8743e1964e..4cb72c735e 100644
--- a/Userland/Libraries/LibCore/Directory.h
+++ b/Userland/Libraries/LibCore/Directory.h
@@ -35,23 +35,23 @@ public:
static ErrorOr<Directory> create(LexicalPath path, CreateDirectories, mode_t creation_mode = 0755);
static ErrorOr<Directory> create(DeprecatedString path, CreateDirectories, mode_t creation_mode = 0755);
- static ErrorOr<Directory> adopt_fd(int fd, Optional<LexicalPath> path = {});
+ static ErrorOr<Directory> adopt_fd(int fd, LexicalPath path);
ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const;
ErrorOr<struct stat> stat() const;
ErrorOr<DirIterator> create_iterator() const;
- ErrorOr<LexicalPath> path() const;
+ LexicalPath const& path() const { return m_path; }
ErrorOr<void> chown(uid_t, gid_t);
static ErrorOr<bool> is_valid_directory(int fd);
private:
- Directory(int directory_fd, Optional<LexicalPath> path);
+ Directory(int directory_fd, LexicalPath path);
static ErrorOr<void> ensure_directory(LexicalPath const& path, mode_t creation_mode = 0755);
- Optional<LexicalPath> m_path;
+ LexicalPath m_path;
int m_directory_fd;
};
@@ -62,10 +62,7 @@ template<>
struct Formatter<Core::Directory> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Core::Directory const& directory)
{
- auto path = directory.path();
- if (path.is_error())
- TRY(builder.put_string("<unknown>"sv));
- TRY(builder.put_string(path.release_value().string()));
+ TRY(builder.put_string(directory.path().string()));
return {};
}
};