summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 13:16:38 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 13:53:14 +0200
commitcae20d2aa9a440e250b6928de3339ea4ee3c67b6 (patch)
tree523953fcc2f644cc764e99dd1cfcbebeaac272bc
parenta27c6f52268a6e85052f166cb9669207d4425b9f (diff)
downloadserenity-cae20d2aa9a440e250b6928de3339ea4ee3c67b6.zip
Kernel: Add FileDescription::try_serialize_absolute_path()
Unlike FileDescription::absolute_path(), this knows that failures can happen and will propagate them to the caller.
-rw-r--r--Kernel/FileSystem/FileDescription.cpp8
-rw-r--r--Kernel/FileSystem/FileDescription.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp
index 6d29027a38..bd0bc23f6b 100644
--- a/Kernel/FileSystem/FileDescription.cpp
+++ b/Kernel/FileSystem/FileDescription.cpp
@@ -344,6 +344,14 @@ KResult FileDescription::close()
return m_file->close();
}
+KResultOr<NonnullOwnPtr<KString>> FileDescription::try_serialize_absolute_path()
+{
+ if (m_custody)
+ return m_custody->try_serialize_absolute_path();
+ // FIXME: Don't go through a String here!
+ return KString::try_create(m_file->absolute_path(*this));
+}
+
String FileDescription::absolute_path() const
{
if (m_custody)
diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h
index 3f1d67c93a..45b9db794b 100644
--- a/Kernel/FileSystem/FileDescription.h
+++ b/Kernel/FileSystem/FileDescription.h
@@ -64,6 +64,7 @@ public:
KResultOr<NonnullOwnPtr<KBuffer>> read_entire_file();
+ KResultOr<NonnullOwnPtr<KString>> try_serialize_absolute_path();
String absolute_path() const;
bool is_direct() const { return m_direct; }