From 3267556ce4068d8790874b807374661997b5e17d Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 17 Jun 2021 11:28:56 +0100 Subject: [PATCH] FileOperation: Accept multiple source arguments You can now list multiple files or directories and they will all be copied to the destination. :^) Note that this means you can pass the same file or directory multiple times. It runs fine, just means that it does unnecessary work. But figuring out if a file is already queued is probably more hassle than it's worth, if it's even possible at all due to symlinks. --- Userland/Services/FileOperation/main.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp index 91f82d8d37..3c06196a72 100644 --- a/Userland/Services/FileOperation/main.cpp +++ b/Userland/Services/FileOperation/main.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,24 +13,24 @@ #include #include -static int perform_copy(String const& source, String const& destination); +static int perform_copy(Vector const& sources, String const& destination); static void report_error(String message); static void report_warning(String message); int main(int argc, char** argv) { String operation; - String source; + Vector sources; String destination; Core::ArgsParser args_parser; args_parser.add_positional_argument(operation, "Operation", "operation", Core::ArgsParser::Required::Yes); - args_parser.add_positional_argument(source, "Source", "source", Core::ArgsParser::Required::Yes); + args_parser.add_positional_argument(sources, "Sources", "sources", Core::ArgsParser::Required::Yes); args_parser.add_positional_argument(destination, "Destination", "destination", Core::ArgsParser::Required::Yes); args_parser.parse(argc, argv); if (operation == "Copy") - return perform_copy(source, destination); + return perform_copy(sources, destination); report_warning(String::formatted("Unknown operation '{}'", operation)); return 0; @@ -98,12 +99,14 @@ static bool collect_work_items(String const& source, String const& destination, return true; } -int perform_copy(String const& source, String const& destination) +int perform_copy(Vector const& sources, String const& destination) { Vector items; - if (!collect_work_items(source, destination, items)) - return 1; + for (auto& source : sources) { + if (!collect_work_items(source, destination, items)) + return 1; + } off_t total_bytes_to_copy = 0; for (auto& item : items)