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

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -13,6 +13,7 @@
#include "app/app.h"
#include "app/app_menus.h"
#include "app/console.h"
#include "app/crash/data_recovery.h"
#include "app/crash/session.h"
#include "app/doc.h"
@ -107,19 +108,31 @@ public:
m_task = new TaskWidget(
TaskWidget::kCannotCancel,
[this](base::task_token& t){
// Warning: This is executed from a worker thread
m_session->deleteBackup(m_backup);
ui::execute_from_ui_thread(
[this]{
onDeleteTaskWidget();
[this](base::task_token& t) {
try {
// Warning: This is executed from a worker thread
m_session->deleteBackup(m_backup);
// We cannot use this->deferDelete() here because it looks
// like the m_task field can be still in use.
setVisible(false);
ui::execute_from_ui_thread(
[this]{
onDeleteTaskWidget();
updateView();
});
// We cannot use this->deferDelete() here because it looks
// like the m_task field can be still in use.
setVisible(false);
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);
updateView();
@ -473,6 +486,7 @@ void DataRecoveryView::onDelete()
int(items.size()))) != 1)
return; // Cancel
Console console;
for (auto item : items)
item->deleteBackup();
}