Skip to content

Commit 610df40

Browse files
committed
fix: Fix Millennium updater failing entirely if a file fails to extract.
1 parent 625a882 commit 610df40

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/core/millennium_updater.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ void MillenniumUpdater::Co_BeginUpdate(const std::string& downloadUrl, const siz
245245
DeleteOldMillenniumVersion();
246246

247247
const auto tempFilePath = std::filesystem::temp_directory_path() / fmt::format("millennium-{}.zip", GenerateUUID());
248+
Logger.Log("Downloading update to temporary file: " + tempFilePath.string());
248249

249250
Http::DownloadWithProgress({ downloadUrl, downloadSize }, tempFilePath, [](size_t downloaded, size_t total)
250251
{
251252
const double progress = (static_cast<double>(downloaded) / total) * 50.0;
252253
RateLimitedLogger("Downloading update assets...", progress);
253254
});
254255

256+
Logger.Log("Extracting and installing update to {}", SystemIO::GetInstallPath().generic_string());
255257
Util::ExtractZipArchive(tempFilePath.string(), SystemIO::GetInstallPath().generic_string(), [](int current, int total, const char*)
256258
{
257259
const double progress = 50.0 + (static_cast<double>(current) / total) * 50.0;

src/util/zip.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <mz_zip_rw.h>
3838

3939
#include "millennium/zip.h"
40+
#include "millennium/logger.h"
4041

4142
#include <filesystem>
4243
#include <functional>
@@ -51,6 +52,7 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
5152

5253
int32_t err = mz_zip_reader_open_file(zip_reader, zip_path.c_str());
5354
if (err != MZ_OK) {
55+
Logger.Log("Failed to open zip file: {} (error: {})", zip_path, err);
5456
mz_zip_reader_delete(&zip_reader);
5557
return false;
5658
}
@@ -68,11 +70,11 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
6870
/** Pre-allocate containers for better performance */
6971
std::unordered_set<std::string> created_dirs;
7072
created_dirs.reserve(file_count / 4);
71-
7273
std::string out_path;
7374
out_path.reserve(dest_dir.length() + 256);
7475

7576
int32_t file_index = 0;
77+
int32_t failed_count = 0;
7678
mz_zip_file* file_info = nullptr;
7779

7880
err = mz_zip_reader_goto_first_entry(zip_reader);
@@ -94,13 +96,14 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
9496
std::filesystem::create_directories(parent_path);
9597
}
9698

97-
err = mz_zip_reader_entry_save_file(zip_reader, out_path.c_str());
98-
if (err != MZ_OK)
99-
break;
99+
int32_t extract_err = mz_zip_reader_entry_save_file(zip_reader, out_path.c_str());
100+
if (extract_err != MZ_OK) {
101+
Logger.Warn("Failed to extract file: {} (error code: {})", out_path, extract_err);
102+
failed_count++;
103+
}
100104
}
101105

102106
file_index++;
103-
104107
if (progress_cb)
105108
progress_cb(file_index, file_count, file_info->filename);
106109

@@ -110,5 +113,9 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
110113
mz_zip_reader_close(zip_reader);
111114
mz_zip_reader_delete(&zip_reader);
112115

116+
if (failed_count > 0) {
117+
Logger.Warn("Extraction completed with {} failed files", failed_count);
118+
}
119+
113120
return (err == MZ_END_OF_LIST || err == MZ_OK);
114-
}
121+
}

0 commit comments

Comments
 (0)