72
72
delete m_archive.data();
75
QString applicationName(qgetenv("APP_ID"));
75
QString applicationName(UCApplication::instance().applicationName());
76
76
if (applicationName.isEmpty()) {
77
applicationName = UCApplication::instance().applicationName();
77
qCritical() << "[StateSaver] Cannot create appstate file, application name not defined.";
79
80
// make sure the path is in sync with https://wiki.ubuntu.com/SecurityTeam/Specifications/ApplicationConfinement
80
81
// the file must be saved under XDG_RUNTIME_DIR/<APP_PKGNAME> path.
81
m_archive = new QSettings(QString("%1/%2/statesaver.appstate")
82
.arg(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation))
83
.arg(applicationName), QSettings::NativeFormat);
82
// NOTE!!: we cannot use QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation)
83
// as that is going to perform a chmod +w on the path, see bug #1359831. Therefore we must
84
// fetch the XDG_RUNTIME_DIR either from QStandardPaths::standardLocations() or from env var
85
// see bug https://bugreports.qt-project.org/browse/QTBUG-41735
86
QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
87
if (runtimeDir.isEmpty()) {
88
runtimeDir = qgetenv("XDG_RUNTIME_DIR");
90
if (runtimeDir.isEmpty()) {
91
qCritical() << "[StateSaver] No XDG_RUNTIME_DIR path set, cannot create appstate file.";
94
m_archive = new QSettings(QString("%1/%2/statesaver.appstate").
96
arg(applicationName), QSettings::NativeFormat);
84
97
m_archive->setFallbacksEnabled(false);