From 602c3fdb3a0975418886e32cf9cc53b45d2f8964 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 26 May 2020 14:52:44 +0300 Subject: [PATCH] AK: Rename FileSystemPath -> LexicalPath And move canonicalized_path() to a static method on LexicalPath. This is to make it clear that FileSystemPath/canonicalized_path() only perform *lexical* canonicalization. --- AK/{FileSystemPath.cpp => LexicalPath.cpp} | 12 +++---- AK/{FileSystemPath.h => LexicalPath.h} | 13 ++++--- ...FileSystemPath.cpp => TestLexicalPath.cpp} | 20 +++++------ AK/URL.cpp | 18 +++++----- Applications/FileManager/DirectoryView.cpp | 1 - Applications/FileManager/FileUtils.cpp | 18 +++++----- Applications/FileManager/PropertiesDialog.cpp | 9 ++--- Applications/FileManager/PropertiesDialog.h | 1 - Applications/FileManager/main.cpp | 14 ++++---- Applications/Help/ManualSectionNode.cpp | 8 ++--- Applications/HexEditor/HexEditorWidget.cpp | 14 ++++---- Applications/HexEditor/HexEditorWidget.h | 4 +-- Applications/TextEditor/TextEditorWidget.cpp | 14 ++++---- Applications/TextEditor/TextEditorWidget.h | 5 +-- DevTools/HackStudio/Editor.cpp | 4 +-- DevTools/HackStudio/Project.cpp | 8 ++--- DevTools/HackStudio/main.cpp | 6 ++-- Kernel/CMakeLists.txt | 2 +- Kernel/FileSystem/VirtualFileSystem.cpp | 20 +++++------ Kernel/Process.cpp | 1 - Libraries/LibC/dlfcn.cpp | 10 +++--- Libraries/LibCore/StandardPaths.cpp | 10 +++--- Libraries/LibGUI/EmojiInputDialog.cpp | 8 ++--- Libraries/LibGUI/FilePicker.cpp | 14 ++++---- Libraries/LibGUI/FilePicker.h | 8 ++--- Libraries/LibGUI/FileSystemModel.cpp | 18 +++++----- Libraries/LibGUI/MultiView.cpp | 1 - Libraries/LibGfx/GIFLoader.cpp | 6 ++-- Libraries/LibGfx/PNGLoader.cpp | 4 +-- Libraries/LibLine/Editor.h | 1 - Libraries/LibVT/TerminalWidget.cpp | 4 +-- Libraries/LibWeb/DOM/Document.cpp | 1 - Libraries/LibWeb/HtmlView.cpp | 4 +-- Services/LaunchServer/Launcher.cpp | 4 +-- Services/SystemMenu/main.cpp | 4 +-- Services/WebServer/Client.cpp | 4 +-- Services/WindowServer/MenuManager.cpp | 1 - Shell/Shell.cpp | 34 +++++++++---------- Userland/basename.cpp | 4 +-- Userland/cp.cpp | 4 +-- Userland/du.cpp | 4 +-- Userland/mkdir.cpp | 10 +++--- Userland/mv.cpp | 4 +-- Userland/pape.cpp | 1 - 44 files changed, 174 insertions(+), 181 deletions(-) rename AK/{FileSystemPath.cpp => LexicalPath.cpp} (92%) rename AK/{FileSystemPath.h => LexicalPath.h} (91%) rename AK/Tests/{TestFileSystemPath.cpp => TestLexicalPath.cpp} (88%) diff --git a/AK/FileSystemPath.cpp b/AK/LexicalPath.cpp similarity index 92% rename from AK/FileSystemPath.cpp rename to AK/LexicalPath.cpp index d79d31f5f60..9400eb01c77 100644 --- a/AK/FileSystemPath.cpp +++ b/AK/LexicalPath.cpp @@ -24,21 +24,21 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include namespace AK { -FileSystemPath::FileSystemPath(const StringView& s) +LexicalPath::LexicalPath(const StringView& s) : m_string(s) { canonicalize(); m_is_valid = true; } -void FileSystemPath::canonicalize() +void LexicalPath::canonicalize() { if (m_string.is_empty()) { m_parts.clear(); @@ -105,14 +105,14 @@ void FileSystemPath::canonicalize() m_string = builder.to_string(); } -bool FileSystemPath::has_extension(const StringView& extension) const +bool LexicalPath::has_extension(const StringView& extension) const { return m_string.ends_with(extension, CaseSensitivity::CaseInsensitive); } -String canonicalized_path(const StringView& path) +String LexicalPath::canonicalized_path(const StringView& path) { - return FileSystemPath(path).string(); + return LexicalPath(path).string(); } } diff --git a/AK/FileSystemPath.h b/AK/LexicalPath.h similarity index 91% rename from AK/FileSystemPath.h rename to AK/LexicalPath.h index 5558945d995..5789b2ca2af 100644 --- a/AK/FileSystemPath.h +++ b/AK/LexicalPath.h @@ -31,10 +31,10 @@ namespace AK { -class FileSystemPath { +class LexicalPath { public: - FileSystemPath() {} - explicit FileSystemPath(const StringView&); + LexicalPath() { } + explicit LexicalPath(const StringView&); bool is_valid() const { return m_is_valid; } bool is_absolute() const { return m_is_absolute; } @@ -49,6 +49,8 @@ public: bool has_extension(const StringView&) const; + static String canonicalized_path(const StringView&); + private: void canonicalize(); @@ -62,9 +64,6 @@ private: bool m_is_absolute { false }; }; -String canonicalized_path(const StringView&); - }; -using AK::canonicalized_path; -using AK::FileSystemPath; +using AK::LexicalPath; diff --git a/AK/Tests/TestFileSystemPath.cpp b/AK/Tests/TestLexicalPath.cpp similarity index 88% rename from AK/Tests/TestFileSystemPath.cpp rename to AK/Tests/TestLexicalPath.cpp index 56887ad192b..5fe6a0efa13 100644 --- a/AK/Tests/TestFileSystemPath.cpp +++ b/AK/Tests/TestLexicalPath.cpp @@ -26,17 +26,17 @@ #include +#include #include -#include TEST_CASE(construct) { - EXPECT_EQ(FileSystemPath().is_valid(), false); + EXPECT_EQ(LexicalPath().is_valid(), false); } TEST_CASE(basic) { - FileSystemPath path("/abc/def/ghi.txt"); + LexicalPath path("/abc/def/ghi.txt"); EXPECT_EQ(path.is_valid(), true); EXPECT_EQ(path.basename(), "ghi.txt"); EXPECT_EQ(path.title(), "ghi"); @@ -48,8 +48,8 @@ TEST_CASE(basic) TEST_CASE(dotdot_coalescing) { - EXPECT_EQ(FileSystemPath("/home/user/../../not/home").string(), "/not/home"); - EXPECT_EQ(FileSystemPath("/../../../../").string(), "/"); + EXPECT_EQ(LexicalPath("/home/user/../../not/home").string(), "/not/home"); + EXPECT_EQ(LexicalPath("/../../../../").string(), "/"); } // Temporarily disabled, as they were broken by commit a3e4dfdf9859a9b955bf4728328f740a47de5851 @@ -59,21 +59,21 @@ TEST_CASE(dotdot_coalescing) TEST_CASE(relative_paths) { { - FileSystemPath path("simple"); + LexicalPath path("simple"); EXPECT_EQ(path.is_valid(), true); EXPECT_EQ(path.string(), "./simple"); EXPECT_EQ(path.parts().size(), 2u); EXPECT_EQ(path.basename(), "simple"); } { - FileSystemPath path("a/relative/path"); + LexicalPath path("a/relative/path"); EXPECT_EQ(path.is_valid(), true); EXPECT_EQ(path.string(), "./a/relative/path"); EXPECT_EQ(path.parts().size(), 4u); EXPECT_EQ(path.basename(), "path"); } { - FileSystemPath path("./././foo"); + LexicalPath path("./././foo"); EXPECT_EQ(path.is_valid(), true); EXPECT_EQ(path.string(), "./foo"); EXPECT_EQ(path.parts().size(), 2u); @@ -81,7 +81,7 @@ TEST_CASE(relative_paths) } { - FileSystemPath path("."); + LexicalPath path("."); EXPECT_EQ(path.is_valid(), true); EXPECT_EQ(path.string(), "."); EXPECT_EQ(path.parts().size(), 1u); @@ -123,4 +123,4 @@ TEST_CASE(has_extension) #endif -TEST_MAIN(FileSystemPath) +TEST_MAIN(LexicalPath) diff --git a/AK/URL.cpp b/AK/URL.cpp index f9bd26aa5e8..24f671e6f1c 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include @@ -314,22 +314,22 @@ URL URL::complete_url(const String& string) const } StringBuilder builder; - FileSystemPath fspath(path()); + LexicalPath lexical_path(path()); builder.append('/'); bool document_url_ends_in_slash = path()[path().length() - 1] == '/'; - for (size_t i = 0; i < fspath.parts().size(); ++i) { - if (i == fspath.parts().size() - 1 && !document_url_ends_in_slash) + for (size_t i = 0; i < lexical_path.parts().size(); ++i) { + if (i == lexical_path.parts().size() - 1 && !document_url_ends_in_slash) break; - builder.append(fspath.parts()[i]); + builder.append(lexical_path.parts()[i]); builder.append('/'); } builder.append(string); auto built = builder.to_string(); - fspath = FileSystemPath(built); + lexical_path = LexicalPath(built); - built = fspath.string(); + built = lexical_path.string(); if (string.ends_with('/') && !built.ends_with('/')) { builder.clear(); builder.append(built); @@ -399,7 +399,7 @@ URL URL::create_with_url_or_path(const String& url_or_path) if (url.is_valid()) return url; - String path = canonicalized_path(url_or_path); + String path = LexicalPath::canonicalized_path(url_or_path); return URL::create_with_file_protocol(path); } @@ -407,7 +407,7 @@ String URL::basename() const { if (!m_valid) return {}; - return FileSystemPath(m_path).basename(); + return LexicalPath(m_path).basename(); } } diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 2efa86825f7..4873277dca4 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -25,7 +25,6 @@ */ #include "DirectoryView.h" -#include #include #include #include diff --git a/Applications/FileManager/FileUtils.cpp b/Applications/FileManager/FileUtils.cpp index 82580e1d2b0..20187415d7b 100644 --- a/Applications/FileManager/FileUtils.cpp +++ b/Applications/FileManager/FileUtils.cpp @@ -25,7 +25,7 @@ */ #include "FileUtils.h" -#include +#include #include #include #include @@ -134,7 +134,7 @@ bool copy_file(const String& src_path, const String& dst_path, const struct stat if (errno != EISDIR) { return false; } - auto dst_dir_path = String::format("%s/%s", dst_path.characters(), FileSystemPath(src_path).basename().characters()); + auto dst_dir_path = String::format("%s/%s", dst_path.characters(), LexicalPath(src_path).basename().characters()); dst_fd = creat(dst_dir_path.characters(), 0666); if (dst_fd < 0) { return false; @@ -186,21 +186,21 @@ String get_duplicate_name(const String& path, int duplicate_count) if (duplicate_count == 0) { return path; } - FileSystemPath fsp(path); + LexicalPath lexical_path(path); StringBuilder duplicated_name; duplicated_name.append('/'); - for (size_t i = 0; i < fsp.parts().size() - 1; ++i) { - duplicated_name.appendf("%s/", fsp.parts()[i].characters()); + for (size_t i = 0; i < lexical_path.parts().size() - 1; ++i) { + duplicated_name.appendf("%s/", lexical_path.parts()[i].characters()); } auto prev_duplicate_tag = String::format("(%d)", duplicate_count); - auto title = fsp.title(); + auto title = lexical_path.title(); if (title.ends_with(prev_duplicate_tag)) { // remove the previous duplicate tag "(n)" so we can add a new tag. title = title.substring(0, title.length() - prev_duplicate_tag.length()); } - duplicated_name.appendf("%s (%d)", fsp.title().characters(), duplicate_count); - if (!fsp.extension().is_empty()) { - duplicated_name.appendf(".%s", fsp.extension().characters()); + duplicated_name.appendf("%s (%d)", lexical_path.title().characters(), duplicate_count); + if (!lexical_path.extension().is_empty()) { + duplicated_name.appendf(".%s", lexical_path.extension().characters()); } return duplicated_name.build(); } diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp index 0813e5fbd01..8caa182dd55 100644 --- a/Applications/FileManager/PropertiesDialog.cpp +++ b/Applications/FileManager/PropertiesDialog.cpp @@ -25,6 +25,7 @@ */ #include "PropertiesDialog.h" +#include #include #include #include @@ -42,8 +43,8 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo : Dialog(parent_window) , m_model(model) { - auto file_path = FileSystemPath(path); - ASSERT(file_path.is_valid()); + auto lexical_path = LexicalPath(path); + ASSERT(lexical_path.is_valid()); auto& main_widget = set_main_widget(); main_widget.set_layout(); @@ -72,8 +73,8 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); m_icon->set_preferred_size(32, 32); - m_name = file_path.basename(); - m_path = file_path.string(); + m_name = lexical_path.basename(); + m_path = lexical_path.string(); m_name_box = file_container.add(); m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); diff --git a/Applications/FileManager/PropertiesDialog.h b/Applications/FileManager/PropertiesDialog.h index 6bb56219364..3ed95541945 100644 --- a/Applications/FileManager/PropertiesDialog.h +++ b/Applications/FileManager/PropertiesDialog.h @@ -26,7 +26,6 @@ #pragma once -#include #include #include #include diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 6ecdb03e9f4..c2d2547dc93 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -27,7 +27,7 @@ #include "DirectoryView.h" #include "FileUtils.h" #include "PropertiesDialog.h" -#include +#include #include #include #include @@ -165,7 +165,7 @@ int run_in_desktop_mode(RefPtr config, String initial_location auto mkdir_action = GUI::Action::create("New directory...", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto new_dir_path = canonicalized_path( + auto new_dir_path = LexicalPath::canonicalized_path( String::format("%s/%s", model->root_path().characters(), input_box->text_value().characters())); @@ -179,7 +179,7 @@ int run_in_desktop_mode(RefPtr config, String initial_location auto touch_action = GUI::Action::create("New file...", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { auto input_box = GUI::InputBox::construct("Enter name:", "New file", window); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto new_file_path = canonicalized_path( + auto new_file_path = LexicalPath::canonicalized_path( String::format("%s/%s", model->root_path().characters(), input_box->text_value().characters())); @@ -323,7 +323,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto new_dir_path = canonicalized_path( + auto new_dir_path = LexicalPath::canonicalized_path( String::format("%s/%s", directory_view.path().characters(), input_box->text_value().characters())); @@ -442,7 +442,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio selected = selected_file_paths(); } else { path = directories_model->full_path(tree_view.selection().first()); - container_dir_path = FileSystemPath(path).basename(); + container_dir_path = LexicalPath(path).basename(); selected = tree_view_selected_file_paths(); } @@ -510,7 +510,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio String message; if (paths.size() == 1) { - message = String::format("Really delete %s?", FileSystemPath(paths[0]).basename().characters()); + message = String::format("Really delete %s?", LexicalPath(paths[0]).basename().characters()); } else { message = String::format("Really delete %d files?", paths.size()); } @@ -791,7 +791,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio continue; auto new_path = String::format("%s/%s", target_node.full_path(directory_view.model()).characters(), - FileSystemPath(url_to_copy.path()).basename().characters()); + LexicalPath(url_to_copy.path()).basename().characters()); if (url_to_copy.path() == new_path) continue; diff --git a/Applications/Help/ManualSectionNode.cpp b/Applications/Help/ManualSectionNode.cpp index 5ac4bc5350f..d6a1237a23f 100644 --- a/Applications/Help/ManualSectionNode.cpp +++ b/Applications/Help/ManualSectionNode.cpp @@ -26,7 +26,7 @@ #include "ManualSectionNode.h" #include "ManualPageNode.h" -#include +#include #include #include #include @@ -46,10 +46,10 @@ void ManualSectionNode::reify_if_needed() const Vector page_names; while (dir_iter.has_next()) { - FileSystemPath file_path(dir_iter.next_path()); - if (file_path.extension() != "md") + LexicalPath lexical_path(dir_iter.next_path()); + if (lexical_path.extension() != "md") continue; - page_names.append(file_path.title()); + page_names.append(lexical_path.title()); } quick_sort(page_names); diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 565cd42c1c9..73bee7a7efb 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -87,7 +87,7 @@ HexEditorWidget::HexEditorWidget() if (valid && file_size > 0) { m_document_dirty = false; m_editor->set_buffer(ByteBuffer::create_zeroed(file_size)); - set_path(FileSystemPath()); + set_path(LexicalPath()); update_title(); } else { GUI::MessageBox::show("Invalid file size entered.", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); @@ -129,7 +129,7 @@ HexEditorWidget::HexEditorWidget() } m_document_dirty = false; - set_path(FileSystemPath(save_path.value())); + set_path(LexicalPath(save_path.value())); dbg() << "Wrote document to " << save_path.value(); }); @@ -211,11 +211,11 @@ HexEditorWidget::~HexEditorWidget() { } -void HexEditorWidget::set_path(const FileSystemPath& file) +void HexEditorWidget::set_path(const LexicalPath& lexical_path) { - m_path = file.string(); - m_name = file.title(); - m_extension = file.extension(); + m_path = lexical_path.string(); + m_name = lexical_path.title(); + m_extension = lexical_path.extension(); update_title(); } @@ -239,7 +239,7 @@ void HexEditorWidget::open_file(const String& path) m_document_dirty = false; m_editor->set_buffer(file->read_all()); // FIXME: On really huge files, this is never going to work. Should really create a framework to fetch data from the file on-demand. - set_path(FileSystemPath(path)); + set_path(LexicalPath(path)); } bool HexEditorWidget::request_close() diff --git a/Applications/HexEditor/HexEditorWidget.h b/Applications/HexEditor/HexEditorWidget.h index 8661a92ccc9..55152518abd 100644 --- a/Applications/HexEditor/HexEditorWidget.h +++ b/Applications/HexEditor/HexEditorWidget.h @@ -27,8 +27,8 @@ #pragma once #include "HexEditor.h" -#include #include +#include #include #include #include @@ -45,7 +45,7 @@ public: private: HexEditorWidget(); - void set_path(const FileSystemPath& file); + void set_path(const LexicalPath& file); void update_title(); RefPtr m_editor; diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 3fb924f7931..d4c0bc33cdf 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -301,7 +301,7 @@ TextEditorWidget::TextEditorWidget() m_document_dirty = false; m_editor->set_text(StringView()); - set_path(FileSystemPath()); + set_path(LexicalPath()); update_title(); }); @@ -333,7 +333,7 @@ TextEditorWidget::TextEditorWidget() } m_document_dirty = false; - set_path(FileSystemPath(save_path.value())); + set_path(LexicalPath(save_path.value())); dbg() << "Wrote document to " << save_path.value(); }); @@ -465,11 +465,11 @@ TextEditorWidget::~TextEditorWidget() { } -void TextEditorWidget::set_path(const FileSystemPath& file) +void TextEditorWidget::set_path(const LexicalPath& lexical_path) { - m_path = file.string(); - m_name = file.title(); - m_extension = file.extension(); + m_path = lexical_path.string(); + m_name = lexical_path.title(); + m_extension = lexical_path.extension(); if (m_extension == "cpp" || m_extension == "h") { m_cpp_highlight->activate(); @@ -508,7 +508,7 @@ void TextEditorWidget::open_sesame(const String& path) m_document_dirty = false; m_document_opening = true; - set_path(FileSystemPath(path)); + set_path(LexicalPath(path)); m_editor->set_focus(true); } diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index b52e826b793..c3bdcd44826 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -26,14 +26,15 @@ #pragma once -#include #include +#include #include #include #include #include #include #include + class TextEditorWidget final : public GUI::Widget { C_OBJECT(TextEditorWidget) public: @@ -47,7 +48,7 @@ public: private: TextEditorWidget(); - void set_path(const FileSystemPath& file); + void set_path(const LexicalPath& file); void update_title(); void update_markdown_preview(); diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index 3e492caa748..fdbaa09651c 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -27,7 +27,7 @@ #include "Editor.h" #include "EditorWrapper.h" #include -#include +#include #include #include #include @@ -137,7 +137,7 @@ static HashMap& man_paths() Core::DirIterator it("/usr/share/man/man2", Core::DirIterator::Flags::SkipDots); while (it.has_next()) { auto path = String::format("/usr/share/man/man2/%s", it.next_path().characters()); - auto title = FileSystemPath(path).title(); + auto title = LexicalPath(path).title(); paths.set(title, path); } } diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp index 348332af99f..e0e4a3bf1ca 100644 --- a/DevTools/HackStudio/Project.cpp +++ b/DevTools/HackStudio/Project.cpp @@ -25,7 +25,7 @@ */ #include "Project.h" -#include +#include #include #include #include @@ -169,7 +169,7 @@ private: Project::Project(const String& path, Vector&& filenames) : m_path(path) { - m_name = FileSystemPath(m_path).basename(); + m_name = LexicalPath(m_path).basename(); m_file_icon = GUI::Icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png")); m_cplusplus_icon = GUI::Icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-cplusplus.png")); @@ -283,7 +283,7 @@ bool Project::save() ProjectFile* Project::get_file(const String& filename) { for (auto& file : m_files) { - if (FileSystemPath(file.name()).string() == FileSystemPath(filename).string()) + if (LexicalPath(file.name()).string() == LexicalPath(filename).string()) return &file; } return nullptr; @@ -307,7 +307,7 @@ void Project::rebuild_tree() root->type = ProjectTreeNode::Type::Project; for (auto& file : m_files) { - FileSystemPath path(file.name()); + LexicalPath path(file.name()); ProjectTreeNode* current = root.ptr(); StringBuilder partial_path; diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 601098f587a..81aa9ac9bd1 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -242,7 +242,7 @@ int main(int argc, char** argv) String message; if (files.size() == 1) { - message = String::format("Really remove %s from the project?", FileSystemPath(files[0]).basename().characters()); + message = String::format("Really remove %s from the project?", LexicalPath(files[0]).basename().characters()); } else { message = String::format("Really remove %d files from the project?", files.size()); } @@ -711,8 +711,8 @@ void run(TerminalWrapper& wrapper) void open_project(String filename) { - FileSystemPath path(filename); - if (chdir(path.dirname().characters()) < 0) { + LexicalPath lexical_path(filename); + if (chdir(lexical_path.dirname().characters()) < 0) { perror("chdir"); exit(1); } diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 5a8ee7f1035..ab1c1dc799b 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -121,10 +121,10 @@ set(KERNEL_SOURCES ) set(AK_SOURCES - ../AK/FileSystemPath.cpp ../AK/FlyString.cpp ../AK/JsonParser.cpp ../AK/JsonValue.cpp + ../AK/LexicalPath.cpp ../AK/LogStream.cpp ../AK/String.cpp ../AK/StringBuilder.cpp diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 2d3c3b1d8af..e4d97772fc9 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include @@ -291,7 +291,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base) if (!parent_inode.metadata().may_write(*Process::current)) return KResult(-EACCES); - FileSystemPath p(path); + LexicalPath p(path); dbg() << "VFS::mknod: '" << p.basename() << "' mode=" << mode << " dev=" << dev << " in " << parent_inode.identifier(); return parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), mode, 0, dev, Process::current->uid(), Process::current->gid()).result(); } @@ -310,7 +310,7 @@ KResultOr> VFS::create(StringView path, int optio auto& parent_inode = parent_custody.inode(); if (!parent_inode.metadata().may_write(*Process::current)) return KResult(-EACCES); - FileSystemPath p(path); + LexicalPath p(path); #ifdef VFS_DEBUG dbg() << "VFS::create: '" << p.basename() << "' in " << parent_inode.identifier(); #endif @@ -349,7 +349,7 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base) if (!parent_inode.metadata().may_write(*Process::current)) return KResult(-EACCES); - FileSystemPath p(path); + LexicalPath p(path); #ifdef VFS_DEBUG dbg() << "VFS::mkdir: '" << p.basename() << "' in " << parent_inode.identifier(); #endif @@ -449,7 +449,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) return KResult(-EACCES); } - auto new_basename = FileSystemPath(new_path).basename(); + auto new_basename = LexicalPath(new_path).basename(); if (!new_custody_or_error.is_error()) { auto& new_custody = *new_custody_or_error.value(); @@ -472,7 +472,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) if (result.is_error()) return result; - result = old_parent_inode.remove_child(FileSystemPath(old_path).basename()); + result = old_parent_inode.remove_child(LexicalPath(old_path).basename()); if (result.is_error()) return result; @@ -555,7 +555,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base) if (old_inode.is_directory()) return KResult(-EPERM); - return parent_inode.add_child(old_inode.identifier(), FileSystemPath(new_path).basename(), old_inode.mode()); + return parent_inode.add_child(old_inode.identifier(), LexicalPath(new_path).basename(), old_inode.mode()); } KResult VFS::unlink(StringView path, Custody& base) @@ -579,7 +579,7 @@ KResult VFS::unlink(StringView path, Custody& base) return KResult(-EACCES); } - auto result = parent_inode.remove_child(FileSystemPath(path).basename()); + auto result = parent_inode.remove_child(LexicalPath(path).basename()); if (result.is_error()) return result; @@ -600,7 +600,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base) if (!parent_inode.metadata().may_write(*Process::current)) return KResult(-EACCES); - FileSystemPath p(linkpath); + LexicalPath p(linkpath); dbg() << "VFS::symlink: '" << p.basename() << "' (-> '" << target << "') in " << parent_inode.identifier(); auto inode_or_error = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), 0120644, 0, 0, Process::current->uid(), Process::current->gid()); if (inode_or_error.is_error()) @@ -649,7 +649,7 @@ KResult VFS::rmdir(StringView path, Custody& base) if (result.is_error()) return result; - return parent_inode.remove_child(FileSystemPath(path).basename()); + return parent_inode.remove_child(LexicalPath(path).basename()); } RefPtr VFS::get_inode(InodeIdentifier inode_id) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 20921c3e2b4..7a4019f3735 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -25,7 +25,6 @@ */ #include -#include #include #include #include diff --git a/Libraries/LibC/dlfcn.cpp b/Libraries/LibC/dlfcn.cpp index d6be5d88677..eaa3c5f7dff 100644 --- a/Libraries/LibC/dlfcn.cpp +++ b/Libraries/LibC/dlfcn.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -70,9 +70,9 @@ void* dlopen(const char* filename, int flags) ASSERT_NOT_REACHED(); } - FileSystemPath file_path(filename); + auto basename = LexicalPath(filename).basename(); - auto existing_elf_object = g_elf_objects.get(file_path.basename()); + auto existing_elf_object = g_elf_objects.get(basename); if (existing_elf_object.has_value()) { return const_cast(existing_elf_object.value()); } @@ -105,11 +105,11 @@ void* dlopen(const char* filename, int flags) return nullptr; } - g_elf_objects.set(file_path.basename(), move(loader)); + g_elf_objects.set(basename, move(loader)); g_dlerror_msg = "Successfully loaded ELF object."; // we have one refcount already - return const_cast(g_elf_objects.get(file_path.basename()).value()); + return const_cast(g_elf_objects.get(basename).value()); } void* dlsym(void* handle, const char* symbol_name) diff --git a/Libraries/LibCore/StandardPaths.cpp b/Libraries/LibCore/StandardPaths.cpp index 6494a1f43c0..c73e16461b3 100644 --- a/Libraries/LibCore/StandardPaths.cpp +++ b/Libraries/LibCore/StandardPaths.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include @@ -37,12 +37,12 @@ namespace Core { String StandardPaths::home_directory() { if (auto* home_env = getenv("HOME")) - return canonicalized_path(home_env); + return LexicalPath::canonicalized_path(home_env); auto* pwd = getpwuid(getuid()); String path = pwd ? pwd->pw_dir : "/"; endpwent(); - return canonicalized_path(path); + return LexicalPath::canonicalized_path(path); } String StandardPaths::desktop_directory() @@ -50,7 +50,7 @@ String StandardPaths::desktop_directory() StringBuilder builder; builder.append(home_directory()); builder.append("/Desktop"); - return canonicalized_path(builder.to_string()); + return LexicalPath::canonicalized_path(builder.to_string()); } String StandardPaths::downloads_directory() @@ -58,7 +58,7 @@ String StandardPaths::downloads_directory() StringBuilder builder; builder.append(home_directory()); builder.append("/Downloads"); - return canonicalized_path(builder.to_string()); + return LexicalPath::canonicalized_path(builder.to_string()); } String StandardPaths::tempfile_directory() diff --git a/Libraries/LibGUI/EmojiInputDialog.cpp b/Libraries/LibGUI/EmojiInputDialog.cpp index 74429fdd5fd..f345cf7f493 100644 --- a/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Libraries/LibGUI/EmojiInputDialog.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include @@ -43,10 +43,10 @@ static Vector supported_emoji_codepoints() Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots); while (dt.has_next()) { auto filename = dt.next_path(); - auto fspath = FileSystemPath(filename); - if (fspath.extension() != "png") + auto lexical_path = LexicalPath(filename); + if (lexical_path.extension() != "png") continue; - auto basename = fspath.basename(); + auto basename = lexical_path.basename(); if (!basename.starts_with("U+")) continue; u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16); diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp index f01b565aa0b..674de7f28f2 100644 --- a/Libraries/LibGUI/FilePicker.cpp +++ b/Libraries/LibGUI/FilePicker.cpp @@ -24,8 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include #include #include @@ -142,9 +142,9 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& auto mkdir_action = Action::create("New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) { auto& input_box = add("Enter name:", "New directory"); if (input_box.exec() == InputBox::ExecOK && !input_box.text_value().is_empty()) { - auto new_dir_path = FileSystemPath(String::format("%s/%s", - m_model->root_path().characters(), - input_box.text_value().characters())) + auto new_dir_path = LexicalPath(String::format("%s/%s", + m_model->root_path().characters(), + input_box.text_value().characters())) .string(); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { @@ -196,7 +196,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& auto& filter_model = (SortingProxyModel&)*m_view->model(); auto local_index = filter_model.map_to_target(index); const FileSystemModel::Node& node = m_model->node(local_index); - FileSystemPath path { node.full_path(m_model) }; + LexicalPath path { node.full_path(m_model) }; clear_preview(); @@ -267,7 +267,7 @@ FilePicker::~FilePicker() { } -void FilePicker::set_preview(const FileSystemPath& path) +void FilePicker::set_preview(const LexicalPath& path) { if (path.has_extension(".png")) { auto bitmap = Gfx::Bitmap::load_from_file(path.string()); @@ -292,7 +292,7 @@ void FilePicker::clear_preview() void FilePicker::on_file_return() { - FileSystemPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters())); + LexicalPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters())); if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) { auto result = MessageBox::show("File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel); diff --git a/Libraries/LibGUI/FilePicker.h b/Libraries/LibGUI/FilePicker.h index 9e67a9caa74..7831cba0c7a 100644 --- a/Libraries/LibGUI/FilePicker.h +++ b/Libraries/LibGUI/FilePicker.h @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include @@ -45,10 +45,10 @@ public: virtual ~FilePicker() override; - FileSystemPath selected_file() const { return m_selected_file; } + LexicalPath selected_file() const { return m_selected_file; } private: - void set_preview(const FileSystemPath&); + void set_preview(const LexicalPath&); void clear_preview(); void on_file_return(); @@ -68,7 +68,7 @@ private: RefPtr m_view; NonnullRefPtr m_model; - FileSystemPath m_selected_file; + LexicalPath m_selected_file; RefPtr m_filename_textbox; RefPtr