From b4ad3f1b37bfea3648f12e185719eeea30f3fd60 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 13 May 2023 19:48:21 +0200 Subject: [PATCH] LookupServer: Prefer File::read_until_eof over DeprecatedFile --- .../Services/LookupServer/MulticastDNS.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp index 7499391a63e..19e84d5e77a 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -119,18 +119,25 @@ ErrorOr MulticastDNS::emit_packet(Packet const& packet, sockaddr_in cons Vector MulticastDNS::local_addresses() const { - auto file = Core::DeprecatedFile::construct("/sys/kernel/net/adapters"); - if (!file->open(Core::OpenMode::ReadOnly)) { - dbgln("Failed to open /sys/kernel/net/adapters: {}", file->error_string()); + auto file_or_error = Core::File::open("/sys/kernel/net/adapters"sv, Core::File::OpenMode::Read); + if (file_or_error.is_error()) { + dbgln("Failed to open /sys/kernel/net/adapters: {}", file_or_error.error()); + return {}; + } + auto file_contents_or_error = file_or_error.value()->read_until_eof(); + if (file_or_error.is_error()) { + dbgln("Cannot read /sys/kernel/net/adapters: {}", file_contents_or_error.error()); + return {}; + } + auto json_or_error = JsonValue::from_string(file_contents_or_error.value()); + if (json_or_error.is_error()) { + dbgln("Invalid JSON(?) in /sys/kernel/net/adapters: {}", json_or_error.error()); return {}; } - auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - Vector addresses; - json.as_array().for_each([&addresses](auto& value) { + json_or_error.value().as_array().for_each([&addresses](auto& value) { auto if_object = value.as_object(); auto address = if_object.get_deprecated_string("ipv4_address"sv).value_or({}); auto ipv4_address = IPv4Address::from_string(address);