1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

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.
This commit is contained in:
Sergey Bugaev 2020-05-26 14:52:44 +03:00 committed by Andreas Kling
parent f746bbda17
commit 602c3fdb3a
44 changed files with 174 additions and 181 deletions

View file

@ -32,7 +32,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/HashMap.h>
#include <AK/RefPtr.h>
#include <AK/ScopeGuard.h>
@ -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<ELF::DynamicLoader*>(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<ELF::DynamicLoader*>(g_elf_objects.get(file_path.basename()).value());
return const_cast<ELF::DynamicLoader*>(g_elf_objects.get(basename).value());
}
void* dlsym(void* handle, const char* symbol_name)

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/StandardPaths.h>
@ -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()

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <AK/Utf32View.h>
#include <LibCore/DirIterator.h>
@ -43,10 +43,10 @@ static Vector<u32> 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);

View file

@ -24,8 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/Function.h>
#include <AK/LexicalPath.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@ -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<InputBox>("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);

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/Optional.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/Dialog.h>
@ -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<MultiView> m_view;
NonnullRefPtr<FileSystemModel> m_model;
FileSystemPath m_selected_file;
LexicalPath m_selected_file;
RefPtr<TextBox> m_filename_textbox;
RefPtr<Label> m_preview_image_label;

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/FileSystemModel.h>
@ -162,24 +162,24 @@ String FileSystemModel::Node::full_path(const FileSystemModel& model) const
}
builder.append('/');
builder.append(name);
return canonicalized_path(builder.to_string());
return LexicalPath::canonicalized_path(builder.to_string());
}
ModelIndex FileSystemModel::index(const StringView& path, int column) const
{
FileSystemPath canonical_path(path);
LexicalPath lexical_path(path);
const Node* node = m_root;
if (canonical_path.string() == "/")
if (lexical_path.string() == "/")
return m_root->index(*this, column);
for (size_t i = 0; i < canonical_path.parts().size(); ++i) {
auto& part = canonical_path.parts()[i];
for (size_t i = 0; i < lexical_path.parts().size(); ++i) {
auto& part = lexical_path.parts()[i];
bool found = false;
for (auto& child : node->children) {
if (child.name == part) {
const_cast<Node&>(child).reify_if_needed(*this);
node = &child;
found = true;
if (i == canonical_path.parts().size() - 1)
if (i == lexical_path.parts().size() - 1)
return child.index(*this, column);
break;
}
@ -198,7 +198,7 @@ String FileSystemModel::full_path(const ModelIndex& index) const
}
FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode)
: m_root_path(canonicalized_path(root_path))
: m_root_path(LexicalPath::canonicalized_path(root_path))
, m_mode(mode)
{
m_directory_icon = Icon::default_icon("filetype-folder");
@ -284,7 +284,7 @@ static String permission_string(mode_t mode)
void FileSystemModel::set_root_path(const StringView& root_path)
{
m_root_path = canonicalized_path(root_path);
m_root_path = LexicalPath::canonicalized_path(root_path);
update();
if (m_root->has_error()) {

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>

View file

@ -26,7 +26,7 @@
#include <AK/BufferStream.h>
#include <AK/ByteBuffer.h>
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/MappedFile.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibGfx/GIFLoader.h>
@ -99,7 +99,7 @@ RefPtr<Gfx::Bitmap> load_gif(const StringView& path)
GIFImageDecoderPlugin gif_decoder((const u8*)mapped_file.data(), mapped_file.size());
auto bitmap = gif_decoder.bitmap();
if (bitmap)
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: %s", bitmap->width(), bitmap->height(), canonicalized_path(path).characters()));
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
return bitmap;
}
@ -536,7 +536,7 @@ GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size)
m_context->data_size = size;
}
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() {}
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() { }
Size GIFImageDecoderPlugin::size()
{

View file

@ -25,7 +25,7 @@
*/
#include <AK/ByteBuffer.h>
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/MappedFile.h>
#include <AK/NetworkOrdered.h>
#include <LibCore/puff.h>
@ -193,7 +193,7 @@ RefPtr<Gfx::Bitmap> load_png(const StringView& path)
return nullptr;
auto bitmap = load_png_impl((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), canonicalized_path(path).characters()));
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
return bitmap;
}

View file

@ -28,7 +28,6 @@
#include <AK/BinarySearch.h>
#include <AK/ByteBuffer.h>
#include <AK/FileSystemPath.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>

View file

@ -26,7 +26,7 @@
#include "TerminalWidget.h"
#include "XtermColors.h"
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
@ -843,7 +843,7 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event)
// Then add them to the context menu.
// FIXME: Adapt this code when we actually support calling LaunchServer with a specific handler in mind.
for (auto& handler : handlers) {
auto af_path = String::format("/res/apps/%s.af", FileSystemPath(handler).basename().characters());
auto af_path = String::format("/res/apps/%s.af", LexicalPath(handler).basename().characters());
auto af = Core::ConfigFile::open(af_path);
auto handler_name = af->read_entry("App", "Name", handler);
auto handler_icon = af->read_entry("Icons", "16x16", {});

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/Timer.h>
#include <LibGUI/Application.h>

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/URL.h>
#include <LibCore/File.h>
#include <LibCore/MimeData.h>
@ -377,7 +377,7 @@ static RefPtr<Document> create_image_document(const ByteBuffer& data, const URL&
auto title_element = create_element(document, "title");
head_element->append_child(title_element);
auto basename = FileSystemPath(url.path()).basename();
auto basename = LexicalPath(url.path()).basename();
auto title_text = adopt(*new Text(document, String::format("%s [%dx%d]", basename.characters(), bitmap->width(), bitmap->height())));
title_element->append_child(title_text);