File indexing completed on 2024-05-19 13:14:44

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 <QStandardPaths>
0011 #include <QString>
0012 
0013 namespace Metadata
0014 {
0015 static QString metadataPath(int pid)
0016 {
0017     const QString name = QStringLiteral("kcrash-metadata/%1.ini").arg(pid);
0018     return QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + name;
0019 }
0020 
0021 // Defined in the header so it can be used by the coredump-helper as well.
0022 static QString resolveMetadataPath(int pid)
0023 {
0024     const QString name = QStringLiteral("kcrash-metadata/%1.ini").arg(pid);
0025     const QString path = QStandardPaths::locate(QStandardPaths::GenericCacheLocation, name);
0026 
0027     if (path.isEmpty() || !QFile::exists(path)) {
0028         qWarning() << "Unable to find file for pid" << pid << "expected at" << name;
0029         return {};
0030     }
0031 
0032     return path;
0033 }
0034 } // namespace Metadata