summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-07 00:43:57 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-08 00:35:27 +0100
commitb2170c11a46cbe8e45c5265a20927dad63dc52b5 (patch)
tree8de277ba71634daa5bb250e449dbd29c3cc3761a
parent0f5477c721c4cd8f1dbbf34eafd348bd248a1f79 (diff)
downloadserenity-b2170c11a46cbe8e45c5265a20927dad63dc52b5.zip
LibCore: Use ErrorOr<T> for Core::File::link_file()
-rw-r--r--Userland/Libraries/LibCore/File.cpp9
-rw-r--r--Userland/Libraries/LibCore/File.h2
2 files changed, 4 insertions, 7 deletions
diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp
index f6aac9e676..dc21704019 100644
--- a/Userland/Libraries/LibCore/File.cpp
+++ b/Userland/Libraries/LibCore/File.cpp
@@ -498,7 +498,7 @@ Result<void, File::CopyError> File::copy_directory(String const& dst_path, Strin
return {};
}
-Result<void, OSError> File::link_file(String const& dst_path, String const& src_path)
+ErrorOr<void> File::link_file(String const& dst_path, String const& src_path)
{
int duplicate_count = 0;
while (access(get_duplicate_name(dst_path, duplicate_count).characters(), F_OK) == 0) {
@@ -507,11 +507,8 @@ Result<void, OSError> File::link_file(String const& dst_path, String const& src_
if (duplicate_count != 0) {
return link_file(get_duplicate_name(dst_path, duplicate_count), src_path);
}
- int rc = symlink(src_path.characters(), dst_path.characters());
- if (rc < 0) {
- return OSError(errno);
- }
-
+ if (symlink(src_path.characters(), dst_path.characters()) < 0)
+ return Error::from_errno(errno);
return {};
}
diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h
index 58989eef74..1b66536b63 100644
--- a/Userland/Libraries/LibCore/File.h
+++ b/Userland/Libraries/LibCore/File.h
@@ -70,7 +70,7 @@ public:
static String real_path_for(String const& filename);
static String read_link(String const& link_path);
- static Result<void, OSError> link_file(String const& dst_path, String const& src_path);
+ static ErrorOr<void> link_file(String const& dst_path, String const& src_path);
struct RemoveError {
String file;