Core: Add wrapper function Application::applicationPid()

This commit is contained in:
wmayer
2024-11-01 15:48:01 +01:00
parent f2c9b9f94e
commit de18adba03
5 changed files with 18 additions and 8 deletions

View File

@@ -47,6 +47,7 @@
#include <sys/sysctl.h>
#endif
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QProcessEnvironment>
@@ -1114,6 +1115,11 @@ Application::TransactionSignaller::~TransactionSignaller() {
}
}
int64_t Application::applicationPid()
{
return QCoreApplication::applicationPid();
}
std::string Application::getHomePath()
{
return mConfig["AppHomePath"];

View File

@@ -399,6 +399,7 @@ public:
static std::map<std::string, std::string> &Config(){return mConfig;}
static int GetARGC(){return _argc;}
static char** GetARGV(){return _argv;}
static int64_t applicationPid();
//@}
/** @name Application directories */

View File

@@ -931,18 +931,21 @@ Document::~Document()
std::string Document::getTransientDirectoryName(const std::string& uuid, const std::string& filename) const
{
// Create a directory name of the form: {ExeName}_Doc_{UUID}_{HASH}_{PID}
std::stringstream s;
std::stringstream out;
QCryptographicHash hash(QCryptographicHash::Sha1);
#if QT_VERSION < QT_VERSION_CHECK(6,3,0)
hash.addData(filename.c_str(), filename.size());
#else
hash.addData(QByteArrayView(filename.c_str(), filename.size()));
#endif
s << App::Application::getUserCachePath() << App::Application::getExecutableName()
<< "_Doc_" << uuid
<< "_" << hash.result().toHex().left(6).constData()
<< "_" << QCoreApplication::applicationPid();
return s.str();
out << App::Application::getUserCachePath() << App::Application::getExecutableName()
<< "_Doc_"
<< uuid
<< "_"
<< hash.result().toHex().left(6).constData()
<< "_"
<< App::Application::applicationPid();
return out.str();
}
//--------------------------------------------------------------------------

View File

@@ -2176,7 +2176,7 @@ void tryRunEventLoop(GUISingleApplication& mainApp)
out << App::Application::getUserCachePath()
<< App::Application::getExecutableName()
<< "_"
<< QCoreApplication::applicationPid()
<< App::Application::applicationPid()
<< ".lock";
// open a lock file with the PID

View File

@@ -654,7 +654,7 @@ void DocumentRecoveryHandler::checkForPreviousCrashes(const std::function<void(Q
for (const QFileInfo& it : locks) {
QString bn = it.baseName();
// ignore the lock file for this instance
QString pid = QString::number(QCoreApplication::applicationPid());
QString pid = QString::number(App::Application::applicationPid());
if (bn.startsWith(exeName) && bn.indexOf(pid) < 0) {
QString fn = it.absoluteFilePath();