File indexing completed on 2024-12-08 07:56:30
0001 /* 0002 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 SPDX-FileCopyrightText: 2019-2021 Harald Sitter <sitter@kde.org> 0004 */ 0005 0006 #pragma once 0007 0008 #include <QDebug> // Don't use categorized logging here to make the header easy to use by the helper daemon 0009 #include <QFile> 0010 #include <QFileInfo> 0011 #include <QStandardPaths> 0012 #include <QString> 0013 0014 namespace Metadata 0015 { 0016 static QString drkonqiMetadataPath(const QString &exe, const QString &bootId, const QString ×tamp, int pid) 0017 { 0018 const QString command = QFileInfo(exe).fileName(); 0019 0020 const QString name = QStringLiteral("drkonqi/crashes/%1.%2.%3.%4.ini").arg(command, bootId, QString::number(pid), timestamp); 0021 return QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + name; 0022 } 0023 0024 // Defined in the header so it can be used by the coredump-helper as well. 0025 static QString resolveKCrashMetadataPath(const QString &exe, const QString &bootId, int pid) 0026 { 0027 const QString command = QFileInfo(exe).fileName(); 0028 0029 const QString nameV2 = QStringLiteral("kcrash-metadata/%1.%2.%3.ini").arg(command, bootId, QString::number(pid)); 0030 const QString pathV2 = QStandardPaths::locate(QStandardPaths::GenericCacheLocation, nameV2); 0031 0032 // Backwards compat for a while. Can be dropped before/after Plasma 6.0 0033 const QString nameV1 = QStringLiteral("kcrash-metadata/%1.ini").arg(pid); 0034 const QString pathV1 = QStandardPaths::locate(QStandardPaths::GenericCacheLocation, nameV1); 0035 0036 for (const auto &path : {pathV2, pathV1}) { 0037 if (!path.isEmpty() && QFile::exists(path)) { 0038 return path; 0039 } 0040 } 0041 0042 qWarning() << "Unable to find file for pid" << pid << "expected at" << nameV2; 0043 return {}; 0044 } 0045 } // namespace Metadata