mirror of https://github.com/aseprite/aseprite.git
				
				
				
			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:
		
							parent
							
								
									ffbe4863ca
								
							
						
					
					
						commit
						2be11cf2f5
					
				| 
						 | 
					@ -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,18 +333,13 @@ 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())
 | 
					    m_backups.erase(it);
 | 
				
			||||||
      m_backups.erase(it);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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"
 | 
				
			||||||
| 
						 | 
					@ -107,19 +108,31 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_task = new TaskWidget(
 | 
					    m_task = new TaskWidget(
 | 
				
			||||||
      TaskWidget::kCannotCancel,
 | 
					      TaskWidget::kCannotCancel,
 | 
				
			||||||
      [this](base::task_token& t){
 | 
					      [this](base::task_token& t) {
 | 
				
			||||||
        // Warning: This is executed from a worker thread
 | 
					        try {
 | 
				
			||||||
        m_session->deleteBackup(m_backup);
 | 
					          // Warning: This is executed from a worker thread
 | 
				
			||||||
        ui::execute_from_ui_thread(
 | 
					          m_session->deleteBackup(m_backup);
 | 
				
			||||||
          [this]{
 | 
					 | 
				
			||||||
            onDeleteTaskWidget();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // We cannot use this->deferDelete() here because it looks
 | 
					          ui::execute_from_ui_thread(
 | 
				
			||||||
            // like the m_task field can be still in use.
 | 
					            [this]{
 | 
				
			||||||
            setVisible(false);
 | 
					              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);
 | 
					    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();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue