Skip to content

Commit

Permalink
refactor: add try catch for CopyRecoverFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed May 8, 2024
1 parent e00d8a1 commit c397223
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/OldBackupHelper/Backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,26 @@ bool CopyRecoverFile(const std::string& worldName) {
// 先重名原来存档,再复制回档文件
auto file_status1 = std::filesystem::status("./worlds/" + worldName, error);
if (error) return false;
if (std::filesystem::exists(file_status1) && std::filesystem::exists(file_status)) {
std::filesystem::rename("./worlds/" + worldName, "./worlds/" + worldName + "_bak");
} else {
return false;
}
std::filesystem::copy(TEMP1_DIR, "./worlds", std::filesystem::copy_options::recursive, error);
if (error.value() != 0) {
SendFeedback(playerUuid, "Failed to copy files!\n" + error.message());
try {
if (std::filesystem::exists(file_status1) && std::filesystem::exists(file_status)) {
std::filesystem::rename("./worlds/" + worldName, "./worlds/" + worldName + "_bak");
} else {
return false;
}
std::filesystem::copy(TEMP1_DIR, "./worlds", std::filesystem::copy_options::recursive, error);
if (error.value() != 0) {
SendFeedback(playerUuid, "Failed to copy files!\n" + error.message());
std::filesystem::remove_all(TEMP1_DIR);
std::filesystem::rename("./worlds/" + worldName + "_bak", "./worlds/" + worldName);
return false;
}
std::filesystem::remove_all(TEMP1_DIR);
std::filesystem::rename("./worlds/" + worldName + "_bak", "./worlds/" + worldName);
std::filesystem::remove_all("./worlds/" + worldName + "_bak");
return true;
} catch (...) {
ll::error_utils::printCurrentException(backup_helper::BackupHelper::getInstance().getSelf().getLogger());
return false;
}
std::filesystem::remove_all(TEMP1_DIR);
std::filesystem::remove_all("./worlds/" + worldName + "_bak");
return true;
}

bool StartBackup() {
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_rules("mode.debug", "mode.release")

add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")

add_requires("levilamina 0.12.1", "simpleini")
add_requires("levilamina 0.12.3", "simpleini")

if not has_config("vs_runtime") then
set_runtimes("MD")
Expand Down

0 comments on commit c397223

Please sign in to comment.