From 6c63cb2a8a4c4cf7b4e7b5ddd9589ddea4dcb22c Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sun, 21 Sep 2025 06:37:41 -0400 Subject: [PATCH] Fix auto_backup. --- source/appstates/BackupMenuState.cpp | 2 +- source/fs/io.cpp | 15 ++------------- source/fs/zip.cpp | 2 ++ source/tasks/backup.cpp | 23 ++++++++++++++++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/source/appstates/BackupMenuState.cpp b/source/appstates/BackupMenuState.cpp index 7efa639..bb20936 100644 --- a/source/appstates/BackupMenuState.cpp +++ b/source/appstates/BackupMenuState.cpp @@ -144,7 +144,7 @@ void BackupMenuState::initialize_static_members() if (sm_backupMenu && sm_slidePanel && sm_menuRenderTarget && sm_panelWidth) { return; } sm_panelWidth = sdl::text::get_width(22, m_controlGuide) + 64; - sm_backupMenu = ui::Menu::create(8, 8, sm_panelWidth - 16, 24, 600); + sm_backupMenu = ui::Menu::create(8, 8, sm_panelWidth - 16, 22, 600); sm_slidePanel = ui::SlideOutPanel::create(sm_panelWidth, ui::SlideOutPanel::Side::Right); sm_menuRenderTarget = sdl::TextureManager::load("backupMenuTarget", sm_panelWidth, 600, SDL_TEXTUREACCESS_TARGET); } diff --git a/source/fs/io.cpp b/source/fs/io.cpp index ba267b6..67e7570 100644 --- a/source/fs/io.cpp +++ b/source/fs/io.cpp @@ -13,14 +13,13 @@ #include #include #include -#include namespace { // Size of buffer shared between threads. - constexpr size_t SIZE_FILE_BUFFER = 0x600000; + // constexpr size_t SIZE_FILE_BUFFER = 0x600000; // This one is just for testing something. - // constexpr size_t SIZE_FILE_BUFFER = 0x200000; + constexpr size_t SIZE_FILE_BUFFER = 0x200000; } // namespace // clang-format off @@ -32,7 +31,6 @@ struct FileThreadStruct : sys::threadpool::DataStruct ssize_t readSize{}; std::unique_ptr sharedBuffer{}; fslib::File *source{}; - std::binary_semaphore writeComplete{0}; }; // clang-format on @@ -46,7 +44,6 @@ static void read_thread_function(sys::threadpool::JobData jobData) ssize_t &readSize = castData->readSize; std::unique_ptr &sharedBuffer = castData->sharedBuffer; fslib::File &source = *castData->source; - auto &writeComplete = castData->writeComplete; const int64_t fileSize = source.get_size(); for (int64_t i = 0; i < fileSize;) @@ -65,8 +62,6 @@ static void read_thread_function(sys::threadpool::JobData jobData) if (localRead == -1) { break; } i += localRead; } - - writeComplete.release(); } void fs::copy_file(const fslib::Path &source, const fslib::Path &destination, sys::ProgressTask *task) @@ -97,7 +92,6 @@ void fs::copy_file(const fslib::Path &source, const fslib::Path &destination, sy bool &bufferReady = sharedData->bufferReady; ssize_t &readSize = sharedData->readSize; auto &sharedBuffer = sharedData->sharedBuffer; - auto &writeComplete = sharedData->writeComplete; sys::threadpool::push_job(read_thread_function, sharedData); for (int64_t i = 0; i < sourceSize; i++) @@ -121,8 +115,6 @@ void fs::copy_file(const fslib::Path &source, const fslib::Path &destination, sy i += localRead; if (task) { task->update_current(static_cast(i)); } } - - writeComplete.acquire(); } void fs::copy_file_commit(const fslib::Path &source, @@ -158,7 +150,6 @@ void fs::copy_file_commit(const fslib::Path &source, bool &bufferReady = sharedData->bufferReady; ssize_t &readSize = sharedData->readSize; auto &sharedBuffer = sharedData->sharedBuffer; - auto &writeComplete = sharedData->writeComplete; int64_t journalCount{}; sys::threadpool::push_job(read_thread_function, sharedData); @@ -196,9 +187,7 @@ void fs::copy_file_commit(const fslib::Path &source, journalCount += localRead; if (task) { task->update_current(static_cast(i)); } } - destFile.close(); - writeComplete.acquire(); const bool commitError = error::fslib(fslib::commit_data_to_file_system(destination.get_device_name())); if (commitError) { ui::PopMessageManager::push_message(popTicks, popCommitFailed); } diff --git a/source/fs/zip.cpp b/source/fs/zip.cpp index 771cd5b..8796264 100644 --- a/source/fs/zip.cpp +++ b/source/fs/zip.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace { @@ -33,6 +34,7 @@ struct ZipIOBase : sys::threadpool::DataStruct ssize_t readSize{}; bool bufferReady{}; std::unique_ptr sharedBuffer{}; + std::binary_semaphore writeComplete{0}; }; struct ZipReadStruct : ZipIOBase diff --git a/source/tasks/backup.cpp b/source/tasks/backup.cpp index b565de3..1274304 100644 --- a/source/tasks/backup.cpp +++ b/source/tasks/backup.cpp @@ -41,6 +41,8 @@ void tasks::backup::create_new_backup_local(sys::threadpool::JobData taskData) if (error::is_null(user) || error::is_null(titleInfo)) { TASK_FINISH_RETURN(task); } const std::string targetString = target.string(); + logger::log("targetString: %s", targetString.c_str()); + const bool hasZipExt = std::strstr(targetString.c_str(), STRING_ZIP_EXT); const uint64_t applicationID = titleInfo->get_application_id(); const FsSaveDataInfo *saveInfo = user->get_save_info_by_id(applicationID); @@ -513,8 +515,19 @@ static void auto_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskD std::string backupName = stringutil::get_formatted_string("AUTO - %s - %s", safeNickname, dateString.c_str()); if (zip) { backupName += STRING_ZIP_EXT; } - taskData->killTask = false; - if (autoUpload && remote) { tasks::backup::create_new_backup_remote(taskData); } + auto tempData = std::make_shared(); + tempData->task = task; + tempData->user = user; + tempData->titleInfo = titleInfo; + tempData->spawningState = spawningState; + tempData->killTask = false; + + if (autoUpload && remote) + { + tempData->remoteName = std::move(backupName); + + tasks::backup::create_new_backup_remote(tempData); + } else { // We're going to get the target dir from the path passed. @@ -522,7 +535,11 @@ static void auto_backup(sys::ProgressTask *task, BackupMenuState::TaskData taskD if (lastSlash == target.NOT_FOUND) { return; } fslib::Path autoTarget{target.sub_path(lastSlash) / backupName}; - tasks::backup::create_new_backup_local(taskData); + logger::log("autoTarget: %s", autoTarget.string().c_str()); + + tempData->path = std::move(autoTarget); + + tasks::backup::create_new_backup_local(tempData); } }