Преглед изворни кода

LibFileSystem+Userland: Return ByteString from absolute_path()

Sam Atkins пре 1 година
родитељ
комит
cdf17efb9a

+ 2 - 2
Userland/Applications/ThemeEditor/main.cpp

@@ -37,7 +37,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No);
     parser.parse(arguments);
 
-    Optional<String> path = {};
+    Optional<ByteString> path = {};
 
     if (auto error_or_path = FileSystem::absolute_path(file_to_edit); !file_to_edit.is_empty() && !error_or_path.is_error())
         path = error_or_path.release_value();
@@ -57,7 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         // Note: This is deferred to ensure that the window has already popped and any error dialog boxes would show up correctly.
         app->event_loop().deferred_invoke(
             [&window, &path, &main_widget]() {
-                auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_byte_string());
+                auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value());
                 if (!response.is_error()) {
                     auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
                     if (load_from_file_result.is_error())

+ 4 - 6
Userland/Libraries/LibFileSystem/FileSystem.cpp

@@ -28,18 +28,16 @@ ErrorOr<ByteString> current_working_directory()
     return Core::System::getcwd();
 }
 
-ErrorOr<String> absolute_path(StringView path)
+ErrorOr<ByteString> absolute_path(StringView path)
 {
     if (exists(path))
-        return TRY(real_path(path));
+        return TRY(real_path(path)).to_byte_string();
 
     if (path.starts_with("/"sv))
-        return TRY(String::from_byte_string(LexicalPath::canonicalized_path(path)));
+        return LexicalPath::canonicalized_path(path);
 
     auto working_directory = TRY(current_working_directory());
-    auto full_path = LexicalPath::join(working_directory, path).string();
-
-    return TRY(String::from_byte_string(LexicalPath::canonicalized_path(full_path)));
+    return LexicalPath::absolute_path(working_directory, path);
 }
 
 ErrorOr<String> real_path(StringView path)

+ 1 - 1
Userland/Libraries/LibFileSystem/FileSystem.h

@@ -19,7 +19,7 @@ namespace FileSystem {
 #define DEFAULT_PATH_SV "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv
 
 ErrorOr<ByteString> current_working_directory();
-ErrorOr<String> absolute_path(StringView path);
+ErrorOr<ByteString> absolute_path(StringView path);
 ErrorOr<String> real_path(StringView path);
 
 bool exists(StringView path);

+ 2 - 2
Userland/Utilities/install.cpp

@@ -35,8 +35,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     ByteString destination_dir = (sources.size() > 1 ? ByteString { destination } : LexicalPath::dirname(destination));
 
     if (create_leading_dest_components) {
-        String destination_dir_absolute = TRY(FileSystem::absolute_path(destination_dir));
-        MUST(Core::Directory::create(destination_dir_absolute.to_byte_string(), Core::Directory::CreateDirectories::Yes));
+        auto destination_dir_absolute = TRY(FileSystem::absolute_path(destination_dir));
+        MUST(Core::Directory::create(destination_dir_absolute, Core::Directory::CreateDirectories::Yes));
     }
 
     for (auto const& source : sources) {

+ 1 - 1
Userland/Utilities/mktemp.cpp

@@ -76,7 +76,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
     if (target_directory.is_empty()) {
         if (!file_template.is_empty()) {
-            auto resolved_path = LexicalPath(TRY(FileSystem::absolute_path(file_template)).to_byte_string());
+            auto resolved_path = LexicalPath(TRY(FileSystem::absolute_path(file_template)));
             final_target_directory = TRY(String::from_utf8(resolved_path.dirname()));
             final_file_template = TRY(String::from_utf8(resolved_path.basename()));
         } else {

+ 1 - 1
Userland/Utilities/sed.cpp

@@ -952,7 +952,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
         pos_args.remove(0);
     }
 
-    HashMap<String, String> paths_to_unveil;
+    HashMap<ByteString, String> paths_to_unveil;
 
     for (auto const& input_filename : TRY(script.input_filenames())) {
         TRY(paths_to_unveil.try_set(TRY(FileSystem::absolute_path(input_filename)), edit_in_place ? "rwc"_string : "r"_string));

+ 1 - 1
Userland/Utilities/tar.cpp

@@ -167,7 +167,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
                 outln("{}", filename);
 
             if (extract) {
-                ByteString absolute_path = TRY(FileSystem::absolute_path(filename)).to_byte_string();
+                auto absolute_path = TRY(FileSystem::absolute_path(filename));
                 auto parent_path = LexicalPath(absolute_path).parent();
                 auto header_mode = TRY(header.mode());