Fix ASSERT deleting a backup session on start when there is no UI

This can happen if the session folder cannto be deleted e.g. when the
folder is not empty (for example if we've copied/created a file in the
session folder manually).
This commit is contained in:
David Capello 2021-01-15 11:43:07 -03:00
parent ffbe4863ca
commit 2be11cf2f5
2 changed files with 33 additions and 24 deletions

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -333,7 +333,6 @@ Doc* Session::restoreBackupRawImages(Backup* backup,
void Session::deleteBackup(Backup* backup) void Session::deleteBackup(Backup* backup)
{ {
try {
auto it = std::find(m_backups.begin(), m_backups.end(), backup); auto it = std::find(m_backups.begin(), m_backups.end(), backup);
ASSERT(it != m_backups.end()); ASSERT(it != m_backups.end());
if (it != m_backups.end()) if (it != m_backups.end())
@ -342,10 +341,6 @@ void Session::deleteBackup(Backup* backup)
if (base::is_directory(backup->dir())) if (base::is_directory(backup->dir()))
deleteDirectory(backup->dir()); deleteDirectory(backup->dir());
} }
catch (const std::exception& ex) {
Console::showException(ex);
}
}
void Session::loadPid() void Session::loadPid()
{ {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -13,6 +13,7 @@
#include "app/app.h" #include "app/app.h"
#include "app/app_menus.h" #include "app/app_menus.h"
#include "app/console.h"
#include "app/crash/data_recovery.h" #include "app/crash/data_recovery.h"
#include "app/crash/session.h" #include "app/crash/session.h"
#include "app/doc.h" #include "app/doc.h"
@ -108,8 +109,10 @@ public:
m_task = new TaskWidget( m_task = new TaskWidget(
TaskWidget::kCannotCancel, TaskWidget::kCannotCancel,
[this](base::task_token& t) { [this](base::task_token& t) {
try {
// Warning: This is executed from a worker thread // Warning: This is executed from a worker thread
m_session->deleteBackup(m_backup); m_session->deleteBackup(m_backup);
ui::execute_from_ui_thread( ui::execute_from_ui_thread(
[this]{ [this]{
onDeleteTaskWidget(); onDeleteTaskWidget();
@ -120,6 +123,16 @@ public:
updateView(); updateView();
}); });
}
catch (const std::exception& ex) {
std::string err = ex.what();
if (!err.empty()) {
ui::execute_from_ui_thread(
[err]{
Console().printf("Error deleting file: %s", err.c_str());
});
}
}
}); });
addChild(m_task); addChild(m_task);
updateView(); updateView();
@ -473,6 +486,7 @@ void DataRecoveryView::onDelete()
int(items.size()))) != 1) int(items.size()))) != 1)
return; // Cancel return; // Cancel
Console console;
for (auto item : items) for (auto item : items)
item->deleteBackup(); item->deleteBackup();
} }