From 680f9c94fca568ed9cea4f5fbd778ebd21510254 Mon Sep 17 00:00:00 2001 From: deniskovalchuk Date: Sun, 17 Sep 2023 02:38:27 +0300 Subject: [PATCH] Bugfix (cmdline): delete a created file in case of download errors --- app/cmdline/src/command_handler.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/cmdline/src/command_handler.cpp b/app/cmdline/src/command_handler.cpp index f83490b..5fd37bb 100644 --- a/app/cmdline/src/command_handler.cpp +++ b/app/cmdline/src/command_handler.cpp @@ -412,7 +412,13 @@ void command_handler::get(const std::vector & args) } transfer_callback transfer_cb; - ftp_client_.download_file(ftp::ostream_adapter(ofs), remote_file, &transfer_cb); + ftp::replies replies = ftp_client_.download_file(ftp::ostream_adapter(ofs), remote_file, &transfer_cb); + + /* Delete the created file in case of errors. */ + if (!replies.is_positive()) + { + std::filesystem::remove(local_file); + } } void command_handler::rename(const std::vector & args)