Fix session 'isRunning' detection (fix #5252)

Before this fix, sometimes files available for recovery aren't
displayed due to the coincidence of the pid number of a crashed
session with the current pid number of the current session. This
coincidence caused Aseprite to falsely detect that it was
the current session.
This commit is contained in:
Gaspar Capello 2025-07-03 17:45:14 -03:00 committed by David Capello
parent 250244c777
commit bf1b4c6f50
4 changed files with 15 additions and 14 deletions

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A. // Copyright (C) 2019-2025 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
@ -139,6 +139,13 @@ DataRecovery::Sessions DataRecovery::sessions()
return copy; return copy;
} }
bool DataRecovery::isRunningSession(const SessionPtr& session) const
{
ASSERT(session);
ASSERT(m_inProgress);
return session->path() == m_inProgress->path();
}
void DataRecovery::searchForSessions() void DataRecovery::searchForSessions()
{ {
Sessions sessions; Sessions sessions;
@ -150,7 +157,7 @@ void DataRecovery::searchForSessions()
RECO_TRACE("RECO: Session '%s' ", itempath.c_str()); RECO_TRACE("RECO: Session '%s' ", itempath.c_str());
SessionPtr session(new Session(&m_config, itempath)); SessionPtr session(new Session(&m_config, itempath));
if (!session->isRunning()) { if (!isRunningSession(session)) {
if ((session->isEmpty()) || (!session->isCrashedSession() && session->isOldSession())) { if ((session->isEmpty()) || (!session->isCrashedSession() && session->isOldSession())) {
RECO_TRACE("to be deleted (%s)\n", RECO_TRACE("to be deleted (%s)\n",
session->isEmpty() ? "is empty" : session->isEmpty() ? "is empty" :

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2025 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
@ -45,6 +45,8 @@ public:
// Returns a copy of the list of sessions that can be recovered. // Returns a copy of the list of sessions that can be recovered.
Sessions sessions(); Sessions sessions();
bool isRunningSession(const SessionPtr& session) const;
// Triggered in the UI-thread from the m_thread using an // Triggered in the UI-thread from the m_thread using an
// ui::execute_from_ui_thread() when the list of sessions is ready // ui::execute_from_ui_thread() when the list of sessions is ready
// to be used. // to be used.

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2019-2025 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
@ -19,12 +19,10 @@
#include "app/crash/write_document.h" #include "app/crash/write_document.h"
#include "app/doc.h" #include "app/doc.h"
#include "app/doc_access.h" #include "app/doc_access.h"
#include "app/file/file.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/fstream_path.h" #include "base/fstream_path.h"
#include "base/process.h"
#include "base/split_string.h" #include "base/split_string.h"
#include "base/string.h" #include "base/string.h"
#include "base/thread.h" #include "base/thread.h"
@ -128,12 +126,6 @@ const Session::Backups& Session::backups()
return m_backups; return m_backups;
} }
bool Session::isRunning()
{
loadPid();
return base::get_process_name(m_pid) == base::get_process_name(base::get_current_process_id());
}
bool Session::isCrashedSession() bool Session::isCrashedSession()
{ {
loadPid(); loadPid();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2019-2025 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
@ -47,9 +47,9 @@ public:
std::string name() const; std::string name() const;
std::string version(); std::string version();
std::string& path() { return m_path; }
const Backups& backups(); const Backups& backups();
bool isRunning();
bool isCrashedSession(); bool isCrashedSession();
bool isOldSession(); bool isOldSession();
bool isEmpty(); bool isEmpty();