diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-06-29 16:46:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-30 11:13:54 +0200 |
commit | fc6d051dfdddc13835548537d025e760ba186b5b (patch) | |
tree | 12a5602dd4efc20f023fea95d390f3e241f6f9cf /Userland/Applications/FileManager | |
parent | 9b8f35259c375f6911b76c38ec37e6d422b26bbe (diff) | |
download | serenity-fc6d051dfdddc13835548537d025e760ba186b5b.zip |
AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.
To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
Diffstat (limited to 'Userland/Applications/FileManager')
-rw-r--r-- | Userland/Applications/FileManager/DirectoryView.cpp | 4 | ||||
-rw-r--r-- | Userland/Applications/FileManager/FileUtils.cpp | 2 | ||||
-rw-r--r-- | Userland/Applications/FileManager/main.cpp | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 1efde7e7b3..8dcb7bd20b 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -55,7 +55,7 @@ static void run_file_operation([[maybe_unused]] FileOperation operation, const S perror("dup2"); _exit(1); } - if (execlp("/bin/FileOperation", "/bin/FileOperation", "Copy", source.characters(), LexicalPath(destination).dirname().characters(), nullptr) < 0) { + if (execlp("/bin/FileOperation", "/bin/FileOperation", "Copy", source.characters(), LexicalPath::dirname(destination).characters(), nullptr) < 0) { perror("execlp"); _exit(1); } @@ -609,7 +609,7 @@ void DirectoryView::handle_drop(const GUI::ModelIndex& index, const GUI::DropEve for (auto& url_to_copy : urls) { if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path()) continue; - auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath(url_to_copy.path()).basename()); + auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath::basename(url_to_copy.path())); if (url_to_copy.path() == new_path) continue; diff --git a/Userland/Applications/FileManager/FileUtils.cpp b/Userland/Applications/FileManager/FileUtils.cpp index ff2fb4f67a..db92e5b6b6 100644 --- a/Userland/Applications/FileManager/FileUtils.cpp +++ b/Userland/Applications/FileManager/FileUtils.cpp @@ -47,7 +47,7 @@ void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window* { String message; if (paths.size() == 1) { - message = String::formatted("Really delete {}?", LexicalPath(paths[0]).basename()); + message = String::formatted("Really delete {}?", LexicalPath::basename(paths[0])); } else { message = String::formatted("Really delete {} files?", paths.size()); } diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 2fac159fcd..3133a647bc 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -187,7 +187,7 @@ void do_paste(const String& target_directory, GUI::Window* window) void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* window) { auto path = selected_file_paths.first(); - auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath { path }.basename()); + auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath::basename(path)); if (auto result = Core::File::link_file(destination, path); result.is_error()) { GUI::MessageBox::show(window, String::formatted("Could not create desktop shortcut:\n{}", result.error()), "File Manager", GUI::MessageBox::Type::Error); @@ -736,7 +736,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio selected = directory_view.selected_file_paths(); } else { path = directories_model->full_path(tree_view.selection().first()); - container_dir_path = LexicalPath(path).basename(); + container_dir_path = LexicalPath::basename(path); selected = tree_view_selected_file_paths(); } @@ -1115,7 +1115,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio for (auto& url_to_copy : urls) { if (!url_to_copy.is_valid() || url_to_copy.path() == directory) continue; - auto new_path = String::formatted("{}/{}", directory, LexicalPath(url_to_copy.path()).basename()); + auto new_path = String::formatted("{}/{}", directory, LexicalPath::basename(url_to_copy.path())); if (url_to_copy.path() == new_path) continue; |