mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
Libraries: Convert DeprecatedFile
usages to LibFileSystem
This commit is contained in:
parent
1dc3ba6ed5
commit
c048cf2004
9 changed files with 51 additions and 33 deletions
|
@ -9,10 +9,11 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibELF/Image.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibGUI/FileIconProvider.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
@ -145,12 +146,12 @@ Icon FileIconProvider::filetype_image_icon()
|
|||
return s_filetype_image_icon;
|
||||
}
|
||||
|
||||
Icon FileIconProvider::icon_for_path(DeprecatedString const& path)
|
||||
Icon FileIconProvider::icon_for_path(StringView path)
|
||||
{
|
||||
struct stat stat;
|
||||
if (::stat(path.characters(), &stat) < 0)
|
||||
auto stat_or_error = Core::System::stat(path);
|
||||
if (stat_or_error.is_error())
|
||||
return s_file_icon;
|
||||
return icon_for_path(path, stat.st_mode);
|
||||
return icon_for_path(path, stat_or_error.release_value().st_mode);
|
||||
}
|
||||
|
||||
Icon FileIconProvider::icon_for_executable(DeprecatedString const& path)
|
||||
|
@ -238,7 +239,7 @@ Icon FileIconProvider::icon_for_executable(DeprecatedString const& path)
|
|||
return icon;
|
||||
}
|
||||
|
||||
Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode)
|
||||
Icon FileIconProvider::icon_for_path(StringView path, mode_t mode)
|
||||
{
|
||||
initialize_if_needed();
|
||||
if (path == "/")
|
||||
|
@ -248,26 +249,27 @@ Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode)
|
|||
return s_home_directory_icon;
|
||||
if (path == Core::StandardPaths::desktop_directory())
|
||||
return s_desktop_directory_icon;
|
||||
if (access(path.characters(), R_OK | X_OK) < 0)
|
||||
if (Core::System::access(path, R_OK | X_OK).is_error())
|
||||
return s_inaccessible_directory_icon;
|
||||
if (path.ends_with(".git"sv))
|
||||
return s_git_directory_icon;
|
||||
return s_directory_icon;
|
||||
}
|
||||
if (S_ISLNK(mode)) {
|
||||
auto raw_symlink_target_or_error = Core::DeprecatedFile::read_link(path);
|
||||
auto raw_symlink_target_or_error = FileSystem::read_link(path);
|
||||
if (raw_symlink_target_or_error.is_error())
|
||||
return s_symlink_icon;
|
||||
|
||||
auto raw_symlink_target = raw_symlink_target_or_error.release_value();
|
||||
if (raw_symlink_target.is_null())
|
||||
return s_symlink_icon;
|
||||
|
||||
DeprecatedString target_path;
|
||||
String target_path;
|
||||
if (raw_symlink_target.starts_with('/')) {
|
||||
target_path = raw_symlink_target;
|
||||
} else {
|
||||
target_path = Core::DeprecatedFile::real_path_for(DeprecatedString::formatted("{}/{}", LexicalPath::dirname(path), raw_symlink_target));
|
||||
auto error_or_path = FileSystem::real_path(DeprecatedString::formatted("{}/{}", LexicalPath::dirname(path), raw_symlink_target));
|
||||
if (error_or_path.is_error())
|
||||
return s_symlink_icon;
|
||||
|
||||
target_path = error_or_path.release_value();
|
||||
}
|
||||
auto target_icon = icon_for_path(target_path);
|
||||
|
||||
|
@ -295,7 +297,7 @@ Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode)
|
|||
if (mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return icon_for_executable(path);
|
||||
|
||||
if (Gfx::Bitmap::is_path_a_supported_image_format(path.view()))
|
||||
if (Gfx::Bitmap::is_path_a_supported_image_format(path))
|
||||
return s_filetype_image_icon;
|
||||
|
||||
for (auto& filetype : s_filetype_icons.keys()) {
|
||||
|
|
|
@ -14,8 +14,8 @@ namespace GUI {
|
|||
|
||||
class FileIconProvider {
|
||||
public:
|
||||
static Icon icon_for_path(DeprecatedString const&, mode_t);
|
||||
static Icon icon_for_path(DeprecatedString const&);
|
||||
static Icon icon_for_path(StringView, mode_t);
|
||||
static Icon icon_for_path(StringView);
|
||||
static Icon icon_for_executable(DeprecatedString const&);
|
||||
|
||||
static Icon filetype_image_icon();
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
#include <AK/QuickSort.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibGUI/AbstractView.h>
|
||||
#include <LibGUI/FileIconProvider.h>
|
||||
#include <LibGUI/FileSystemModel.h>
|
||||
|
@ -63,11 +63,11 @@ bool FileSystemModel::Node::fetch_data(DeprecatedString const& full_path, bool i
|
|||
mtime = st.st_mtime;
|
||||
|
||||
if (S_ISLNK(mode)) {
|
||||
auto sym_link_target_or_error = Core::DeprecatedFile::read_link(full_path);
|
||||
auto sym_link_target_or_error = FileSystem::read_link(full_path);
|
||||
if (sym_link_target_or_error.is_error())
|
||||
perror("readlink");
|
||||
else {
|
||||
symlink_target = sym_link_target_or_error.release_value();
|
||||
symlink_target = sym_link_target_or_error.release_value().to_deprecated_string();
|
||||
if (symlink_target.is_null())
|
||||
perror("readlink");
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ Variant FileSystemModel::data(ModelIndex const& index, ModelRole role) const
|
|||
Icon FileSystemModel::icon_for(Node const& node) const
|
||||
{
|
||||
if (node.full_path() == "/")
|
||||
return FileIconProvider::icon_for_path("/");
|
||||
return FileIconProvider::icon_for_path("/"sv);
|
||||
|
||||
if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) {
|
||||
if (!node.thumbnail) {
|
||||
|
|
|
@ -110,7 +110,7 @@ void PathBreadcrumbbar::set_current_path(DeprecatedString const& new_path)
|
|||
} else {
|
||||
m_breadcrumbbar->clear_segments();
|
||||
|
||||
m_breadcrumbbar->append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/");
|
||||
m_breadcrumbbar->append_segment("/", GUI::FileIconProvider::icon_for_path("/"sv).bitmap_for_size(16), "/", "/");
|
||||
StringBuilder builder;
|
||||
|
||||
for (auto& part : lexical_path.parts()) {
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/TemporaryChange.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/AutocompleteProvider.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue