From 571cd9338224a2e3ed259f03eb0563143e38f0a2 Mon Sep 17 00:00:00 2001 From: ck Date: Wed, 15 May 2024 16:08:30 +0800 Subject: [PATCH] chore: make sure autostart dir existed mkdir if autostart dir not existed --- src/dbus/applicationservice.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index c43a9c6..6f0c9b3 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -652,7 +652,14 @@ void ApplicationService::setAutoStart(bool autostart) noexcept return; } - auto fileName = QDir{getAutoStartDirs().first()}.filePath(m_desktopSource.desktopId() + ".desktop"); + QDir startDir (getAutoStartDirs().first()); + if (!startDir.exists() && !startDir.mkpath(startDir.path())) { + qWarning() << "mkpath " << startDir.path() << "failed"; + safe_sendErrorReply(QDBusError::InternalError); + return; + } + + auto fileName = startDir.filePath(m_desktopSource.desktopId() + ".desktop"); QFile autostartFile{fileName}; if (!autostartFile.open(QFile::WriteOnly | QFile::Text | QFile::Truncate)) { qWarning() << "open file" << fileName << "failed:" << autostartFile.error();