2023-03-22 00:32:08 +11:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
|
2023-03-22 00:32:08 +11:00
|
|
|
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-01-15 17:24:00 +00:00
|
|
|
#include <AK/ByteString.h>
|
2023-03-22 00:32:08 +11:00
|
|
|
#include <AK/Error.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
|
|
|
|
namespace FileSystem {
|
|
|
|
|
|
|
|
#define DEFAULT_PATH "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"
|
|
|
|
#define DEFAULT_PATH_SV "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv
|
|
|
|
|
2024-01-15 16:01:39 +00:00
|
|
|
ErrorOr<ByteString> current_working_directory();
|
2024-01-15 16:10:46 +00:00
|
|
|
ErrorOr<ByteString> absolute_path(StringView path);
|
2024-01-15 16:23:24 +00:00
|
|
|
ErrorOr<ByteString> real_path(StringView path);
|
2023-03-22 00:32:08 +11:00
|
|
|
|
|
|
|
bool exists(StringView path);
|
|
|
|
bool exists(int fd);
|
|
|
|
|
2023-07-07 00:29:31 +12:00
|
|
|
bool is_regular_file(StringView path);
|
|
|
|
bool is_regular_file(int fd);
|
|
|
|
|
2023-03-22 00:32:08 +11:00
|
|
|
bool is_directory(StringView path);
|
|
|
|
bool is_directory(int fd);
|
|
|
|
|
|
|
|
bool is_link(StringView path);
|
|
|
|
bool is_link(int fd);
|
|
|
|
|
|
|
|
enum class RecursionMode {
|
|
|
|
Allowed,
|
|
|
|
Disallowed
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class LinkMode {
|
|
|
|
Allowed,
|
|
|
|
Disallowed
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class AddDuplicateFileMarker {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class PreserveMode {
|
|
|
|
Nothing = 0,
|
|
|
|
Permissions = (1 << 0),
|
|
|
|
Ownership = (1 << 1),
|
|
|
|
Timestamps = (1 << 2),
|
|
|
|
};
|
|
|
|
AK_ENUM_BITWISE_OPERATORS(PreserveMode);
|
|
|
|
|
|
|
|
ErrorOr<void> copy_file(StringView destination_path, StringView source_path, struct stat const& source_stat, Core::File& source, PreserveMode = PreserveMode::Nothing);
|
|
|
|
ErrorOr<void> copy_directory(StringView destination_path, StringView source_path, struct stat const& source_stat, LinkMode = LinkMode::Disallowed, PreserveMode = PreserveMode::Nothing);
|
|
|
|
ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes, PreserveMode = PreserveMode::Nothing);
|
2023-07-06 20:49:14 +12:00
|
|
|
ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode = PreserveMode::Nothing);
|
2023-03-22 00:32:08 +11:00
|
|
|
ErrorOr<void> remove(StringView path, RecursionMode);
|
2024-01-16 12:05:18 +04:00
|
|
|
ErrorOr<off_t> size_from_stat(StringView path);
|
2024-01-16 14:08:05 +04:00
|
|
|
ErrorOr<off_t> size_from_fstat(int fd);
|
2023-03-22 00:32:08 +11:00
|
|
|
bool can_delete_or_move(StringView path);
|
|
|
|
|
|
|
|
}
|