Fix auto_backup.

This commit is contained in:
J-D-K 2025-09-21 06:37:41 -04:00
parent d2c6a1e243
commit 6c63cb2a8a
4 changed files with 25 additions and 17 deletions

View File

@ -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);
}

View File

@ -13,14 +13,13 @@
#include <cstring>
#include <memory>
#include <mutex>
#include <semaphore>
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<sys::Byte[]> 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<sys::Byte[]> &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<double>(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<double>(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); }

View File

@ -14,6 +14,7 @@
#include <ctime>
#include <memory>
#include <mutex>
#include <semaphore>
namespace
{
@ -33,6 +34,7 @@ struct ZipIOBase : sys::threadpool::DataStruct
ssize_t readSize{};
bool bufferReady{};
std::unique_ptr<sys::Byte[]> sharedBuffer{};
std::binary_semaphore writeComplete{0};
};
struct ZipReadStruct : ZipIOBase

View File

@ -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<BackupMenuState::DataStruct>();
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);
}
}