From 56d7869a211b885affcd217ebec26868bb903395 Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Thu, 23 Feb 2023 19:23:24 +0100 Subject: [PATCH] Fix cleanup --- src/client/updater/file_updater.cpp | 21 +++++++++++++++++---- src/client/updater/file_updater.hpp | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/client/updater/file_updater.cpp b/src/client/updater/file_updater.cpp index 508cda49..fedc43ad 100644 --- a/src/client/updater/file_updater.cpp +++ b/src/client/updater/file_updater.cpp @@ -335,11 +335,11 @@ namespace updater return; } - this->cleanup_root_directory(); + this->cleanup_root_directory(files); this->cleanup_data_directory(files); } - void file_updater::cleanup_root_directory() const + void file_updater::cleanup_root_directory(const std::vector& files) const { const auto existing_files = utils::io::list_files(this->base_); for (const auto& file : existing_files) @@ -350,8 +350,21 @@ namespace updater continue; } - std::error_code code{}; - std::filesystem::remove_all(file, code); + bool found = false; + for (const auto& wantedFile : files) + { + if (wantedFile.name == entry) + { + found = true; + break; + } + } + + if (!found) + { + std::error_code code{}; + std::filesystem::remove_all(file, code); + } } } diff --git a/src/client/updater/file_updater.hpp b/src/client/updater/file_updater.hpp index 626ef134..b5e09c40 100644 --- a/src/client/updater/file_updater.hpp +++ b/src/client/updater/file_updater.hpp @@ -34,7 +34,7 @@ namespace updater void delete_old_process_file() const; void cleanup_directories(const std::vector& files) const; - void cleanup_root_directory() const; + void cleanup_root_directory(const std::vector& files) const; void cleanup_data_directory(const std::vector& files) const; }; }