From b284e525f38ac502c85ac77d2075588ae33958f8 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 22 Jul 2023 12:43:27 +0100 Subject: [PATCH] FileOperation: Replace LibC `rename()` call with LibCore equivalent --- Userland/Services/FileOperation/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp index 1080b6331a..f80302a062 100644 --- a/Userland/Services/FileOperation/main.cpp +++ b/Userland/Services/FileOperation/main.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include struct WorkItem { @@ -300,23 +299,24 @@ ErrorOr execute_work_items(Vector const& items) case WorkItem::Type::MoveFile: { DeprecatedString destination = item.destination; while (true) { - if (rename(item.source.characters(), destination.characters()) == 0) { + auto maybe_error = Core::System::rename(item.source, destination); + if (!maybe_error.is_error()) { item_done += item.size; executed_work_bytes += item.size; print_progress(); break; } - auto original_errno = errno; + auto error_code = maybe_error.release_error().code(); - if (original_errno == EEXIST) { + if (error_code == EEXIST) { destination = deduplicate_destination_file_name(destination); continue; } - if (original_errno != EXDEV) { + if (error_code != EXDEV) { // FIXME: Return the formatted string directly. There is no way to do this right now without the temporary going out of scope and being destroyed. - report_warning(DeprecatedString::formatted("Failed to move {}: {}", item.source, strerror(original_errno))); - return Error::from_errno(original_errno); + report_warning(DeprecatedString::formatted("Failed to move {}: {}", item.source, strerror(error_code))); + return Error::from_errno(error_code); } // EXDEV means we have to copy the file data and then remove the original