diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 08deda1f4d..c469105fbf 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -135,6 +135,7 @@ target_link_libraries(pkill PRIVATE LibRegex) target_link_libraries(pls PRIVATE LibCrypt) target_link_libraries(pro PRIVATE LibFileSystem LibProtocol LibHTTP) target_link_libraries(readlink PRIVATE LibFileSystem) +target_link_libraries(realpath PRIVATE LibFileSystem) target_link_libraries(run-tests PRIVATE LibCoredump LibDebug LibFileSystem LibRegex) target_link_libraries(rm PRIVATE LibFileSystem) target_link_libraries(sed PRIVATE LibRegex LibFileSystem) diff --git a/Userland/Utilities/realpath.cpp b/Userland/Utilities/realpath.cpp index f0f623a978..c396da8905 100644 --- a/Userland/Utilities/realpath.cpp +++ b/Userland/Utilities/realpath.cpp @@ -1,33 +1,38 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2023, Tim Ledbetter * * SPDX-License-Identifier: BSD-2-Clause */ #include #include +#include #include -#include -#include ErrorOr serenity_main(Main::Arguments arguments) { TRY(Core::System::pledge("stdio rpath")); - DeprecatedString path; + Vector paths; Core::ArgsParser args_parser; args_parser.set_general_help( "Show the 'real' path of a file, by resolving all symbolic links along the way."); - args_parser.add_positional_argument(path, "Path to resolve", "path"); + args_parser.add_positional_argument(paths, "Path to resolve", "paths"); args_parser.parse(arguments); - char* value = realpath(path.characters(), nullptr); - if (value == nullptr) { - perror("realpath"); - return 1; + auto has_errors = false; + for (auto path : paths) { + auto resolved_path_or_error = FileSystem::real_path(path); + if (resolved_path_or_error.is_error()) { + warnln("realpath: {}: {}", path, strerror(resolved_path_or_error.error().code())); + has_errors = true; + continue; + } + + outln("{}", resolved_path_or_error.release_value()); } - outln("{}", value); - free(value); - return 0; + + return has_errors ? 1 : 0; }