mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibFileSystem: Add FileSystem::move_file
This is effectively a rename that falls back to a copy if the destination is on a different mount point than the source.
This commit is contained in:
parent
640d48255b
commit
a5fd80a336
2 changed files with 19 additions and 0 deletions
|
@ -298,6 +298,24 @@ ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView sou
|
||||||
return copy_file(final_destination_path, source_path, source_stat, *source, preserve_mode);
|
return copy_file(final_destination_path, source_path, source_stat, *source, preserve_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode preserve_mode)
|
||||||
|
{
|
||||||
|
auto maybe_error = Core::System::rename(source_path, destination_path);
|
||||||
|
if (!maybe_error.is_error())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (!maybe_error.error().is_errno() || maybe_error.error().code() != EXDEV)
|
||||||
|
return maybe_error;
|
||||||
|
|
||||||
|
auto source = TRY(Core::File::open(source_path, Core::File::OpenMode::Read));
|
||||||
|
|
||||||
|
auto source_stat = TRY(Core::System::fstat(source->fd()));
|
||||||
|
|
||||||
|
TRY(copy_file(destination_path, source_path, source_stat, *source, preserve_mode));
|
||||||
|
|
||||||
|
return Core::System::unlink(source_path);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> remove(StringView path, RecursionMode mode)
|
ErrorOr<void> remove(StringView path, RecursionMode mode)
|
||||||
{
|
{
|
||||||
if (is_directory(path) && mode == RecursionMode::Allowed) {
|
if (is_directory(path) && mode == RecursionMode::Allowed) {
|
||||||
|
|
|
@ -66,6 +66,7 @@ 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_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_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);
|
ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes, PreserveMode = PreserveMode::Nothing);
|
||||||
|
ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode = PreserveMode::Nothing);
|
||||||
ErrorOr<void> remove(StringView path, RecursionMode);
|
ErrorOr<void> remove(StringView path, RecursionMode);
|
||||||
ErrorOr<size_t> size(StringView path);
|
ErrorOr<size_t> size(StringView path);
|
||||||
bool can_delete_or_move(StringView path);
|
bool can_delete_or_move(StringView path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue