mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:45:09 +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,7 +9,7 @@
|
||||||
#include <AK/ScopedValueRollback.h>
|
#include <AK/ScopedValueRollback.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/API/Unveil.h>
|
#include <Kernel/API/Unveil.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <bits/pthread_cancel.h>
|
#include <bits/pthread_cancel.h>
|
||||||
|
@ -189,7 +189,7 @@ int execvpe(char const* filename, char* const argv[], char* const envp[])
|
||||||
|
|
||||||
ScopedValueRollback errno_rollback(errno);
|
ScopedValueRollback errno_rollback(errno);
|
||||||
|
|
||||||
// TODO: Make this use the PATH search implementation from Core::DeprecatedFile.
|
// TODO: Make this use the PATH search implementation from LibFileSystem.
|
||||||
DeprecatedString path = getenv("PATH");
|
DeprecatedString path = getenv("PATH");
|
||||||
if (path.is_empty())
|
if (path.is_empty())
|
||||||
path = DEFAULT_PATH;
|
path = DEFAULT_PATH;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibFileSystemAccessClient/Client.h>
|
#include <LibFileSystemAccessClient/Client.h>
|
||||||
#include <LibGUI/ConnectionToWindowServer.h>
|
#include <LibGUI/ConnectionToWindowServer.h>
|
||||||
|
@ -42,7 +41,7 @@ Result Client::request_file_read_only_approved(GUI::Window* parent_window, Depre
|
||||||
if (path.starts_with('/')) {
|
if (path.starts_with('/')) {
|
||||||
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, path);
|
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, path);
|
||||||
} else {
|
} else {
|
||||||
auto full_path = LexicalPath::join(Core::DeprecatedFile::current_working_directory(), path).string();
|
auto full_path = LexicalPath::join(TRY(FileSystem::current_working_directory()), path).string();
|
||||||
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, full_path);
|
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, full_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ Result Client::request_file(GUI::Window* parent_window, DeprecatedString const&
|
||||||
if (path.starts_with('/')) {
|
if (path.starts_with('/')) {
|
||||||
async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode);
|
async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode);
|
||||||
} else {
|
} else {
|
||||||
auto full_path = LexicalPath::join(Core::DeprecatedFile::current_working_directory(), path).string();
|
auto full_path = LexicalPath::join(TRY(FileSystem::current_working_directory()), path).string();
|
||||||
async_request_file(id, parent_window_server_client_id, parent_window_id, full_path, mode);
|
async_request_file(id, parent_window_server_client_id, parent_window_id, full_path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,11 @@
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibGUI/FileIconProvider.h>
|
#include <LibGUI/FileIconProvider.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
@ -145,12 +146,12 @@ Icon FileIconProvider::filetype_image_icon()
|
||||||
return s_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;
|
auto stat_or_error = Core::System::stat(path);
|
||||||
if (::stat(path.characters(), &stat) < 0)
|
if (stat_or_error.is_error())
|
||||||
return s_file_icon;
|
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)
|
Icon FileIconProvider::icon_for_executable(DeprecatedString const& path)
|
||||||
|
@ -238,7 +239,7 @@ Icon FileIconProvider::icon_for_executable(DeprecatedString const& path)
|
||||||
return icon;
|
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();
|
initialize_if_needed();
|
||||||
if (path == "/")
|
if (path == "/")
|
||||||
|
@ -248,26 +249,27 @@ Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode)
|
||||||
return s_home_directory_icon;
|
return s_home_directory_icon;
|
||||||
if (path == Core::StandardPaths::desktop_directory())
|
if (path == Core::StandardPaths::desktop_directory())
|
||||||
return s_desktop_directory_icon;
|
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;
|
return s_inaccessible_directory_icon;
|
||||||
if (path.ends_with(".git"sv))
|
if (path.ends_with(".git"sv))
|
||||||
return s_git_directory_icon;
|
return s_git_directory_icon;
|
||||||
return s_directory_icon;
|
return s_directory_icon;
|
||||||
}
|
}
|
||||||
if (S_ISLNK(mode)) {
|
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())
|
if (raw_symlink_target_or_error.is_error())
|
||||||
return s_symlink_icon;
|
return s_symlink_icon;
|
||||||
|
|
||||||
auto raw_symlink_target = raw_symlink_target_or_error.release_value();
|
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('/')) {
|
if (raw_symlink_target.starts_with('/')) {
|
||||||
target_path = raw_symlink_target;
|
target_path = raw_symlink_target;
|
||||||
} else {
|
} 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);
|
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))
|
if (mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||||
return icon_for_executable(path);
|
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;
|
return s_filetype_image_icon;
|
||||||
|
|
||||||
for (auto& filetype : s_filetype_icons.keys()) {
|
for (auto& filetype : s_filetype_icons.keys()) {
|
||||||
|
|
|
@ -14,8 +14,8 @@ namespace GUI {
|
||||||
|
|
||||||
class FileIconProvider {
|
class FileIconProvider {
|
||||||
public:
|
public:
|
||||||
static Icon icon_for_path(DeprecatedString const&, mode_t);
|
static Icon icon_for_path(StringView, mode_t);
|
||||||
static Icon icon_for_path(DeprecatedString const&);
|
static Icon icon_for_path(StringView);
|
||||||
static Icon icon_for_executable(DeprecatedString const&);
|
static Icon icon_for_executable(DeprecatedString const&);
|
||||||
|
|
||||||
static Icon filetype_image_icon();
|
static Icon filetype_image_icon();
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibGUI/AbstractView.h>
|
#include <LibGUI/AbstractView.h>
|
||||||
#include <LibGUI/FileIconProvider.h>
|
#include <LibGUI/FileIconProvider.h>
|
||||||
#include <LibGUI/FileSystemModel.h>
|
#include <LibGUI/FileSystemModel.h>
|
||||||
|
@ -63,11 +63,11 @@ bool FileSystemModel::Node::fetch_data(DeprecatedString const& full_path, bool i
|
||||||
mtime = st.st_mtime;
|
mtime = st.st_mtime;
|
||||||
|
|
||||||
if (S_ISLNK(mode)) {
|
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())
|
if (sym_link_target_or_error.is_error())
|
||||||
perror("readlink");
|
perror("readlink");
|
||||||
else {
|
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())
|
if (symlink_target.is_null())
|
||||||
perror("readlink");
|
perror("readlink");
|
||||||
}
|
}
|
||||||
|
@ -613,7 +613,7 @@ Variant FileSystemModel::data(ModelIndex const& index, ModelRole role) const
|
||||||
Icon FileSystemModel::icon_for(Node const& node) const
|
Icon FileSystemModel::icon_for(Node const& node) const
|
||||||
{
|
{
|
||||||
if (node.full_path() == "/")
|
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 (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) {
|
||||||
if (!node.thumbnail) {
|
if (!node.thumbnail) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ void PathBreadcrumbbar::set_current_path(DeprecatedString const& new_path)
|
||||||
} else {
|
} else {
|
||||||
m_breadcrumbbar->clear_segments();
|
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;
|
StringBuilder builder;
|
||||||
|
|
||||||
for (auto& part : lexical_path.parts()) {
|
for (auto& part : lexical_path.parts()) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/AutocompleteProvider.h>
|
#include <LibGUI/AutocompleteProvider.h>
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
|
||||||
|
@ -142,7 +141,11 @@ Optional<Interface&> Parser::resolve_import(auto path)
|
||||||
if (!FileSystem::exists(include_path))
|
if (!FileSystem::exists(include_path))
|
||||||
report_parsing_error(DeprecatedString::formatted("{}: No such file or directory", include_path), filename, input, lexer.tell());
|
report_parsing_error(DeprecatedString::formatted("{}: No such file or directory", include_path), filename, input, lexer.tell());
|
||||||
|
|
||||||
auto real_path = Core::DeprecatedFile::real_path_for(include_path);
|
auto real_path_error_or = FileSystem::real_path(include_path);
|
||||||
|
if (real_path_error_or.is_error())
|
||||||
|
report_parsing_error(DeprecatedString::formatted("Failed to resolve path {}: {}", include_path, real_path_error_or.error()), filename, input, lexer.tell());
|
||||||
|
auto real_path = real_path_error_or.release_value().to_deprecated_string();
|
||||||
|
|
||||||
if (top_level_resolved_imports().contains(real_path))
|
if (top_level_resolved_imports().contains(real_path))
|
||||||
return *top_level_resolved_imports().find(real_path)->value;
|
return *top_level_resolved_imports().find(real_path)->value;
|
||||||
|
|
||||||
|
@ -925,7 +928,12 @@ void resolve_function_typedefs(Interface& interface, FunctionType& function)
|
||||||
|
|
||||||
Interface& Parser::parse()
|
Interface& Parser::parse()
|
||||||
{
|
{
|
||||||
auto this_module = Core::DeprecatedFile::real_path_for(filename);
|
auto this_module_or_error = FileSystem::real_path(filename);
|
||||||
|
if (this_module_or_error.is_error()) {
|
||||||
|
report_parsing_error(DeprecatedString::formatted("Failed to resolve path '{}': {}", filename, this_module_or_error.error()), filename, input, 0);
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
auto this_module = this_module_or_error.release_value().to_deprecated_string();
|
||||||
|
|
||||||
auto interface_ptr = make<Interface>();
|
auto interface_ptr = make<Interface>();
|
||||||
auto& interface = *interface_ptr;
|
auto& interface = *interface_ptr;
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibTest/JavaScriptTestRunner.h>
|
#include <LibTest/JavaScriptTestRunner.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -177,8 +176,19 @@ int main(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
test_root = Core::DeprecatedFile::real_path_for(test_root);
|
auto test_root_or_error = FileSystem::real_path(test_root);
|
||||||
common_path = Core::DeprecatedFile::real_path_for(common_path);
|
if (test_root_or_error.is_error()) {
|
||||||
|
warnln("Failed to resolve test root: {}", test_root_or_error.error());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
test_root = test_root_or_error.release_value().to_deprecated_string();
|
||||||
|
|
||||||
|
auto common_path_or_error = FileSystem::real_path(common_path);
|
||||||
|
if (common_path_or_error.is_error()) {
|
||||||
|
warnln("Failed to resolve common path: {}", common_path_or_error.error());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
common_path = common_path_or_error.release_value().to_deprecated_string();
|
||||||
|
|
||||||
if (chdir(test_root.characters()) < 0) {
|
if (chdir(test_root.characters()) < 0) {
|
||||||
auto saved_errno = errno;
|
auto saved_errno = errno;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue