Skip to content

Commit

Permalink
Creaate LaunchAgents directory if it doesn't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
erikjv authored and Camila San Martin Ayres committed Jan 14, 2024
1 parent b34d731 commit 0a23565
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/common/utility_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
static Result<void, QString> writePlistToFile(NSString *plistFile, NSDictionary *plist)
{
NSError *error = nil;

// Check if the directory exists. On a fresh installation for example, the directory does not
// exist, so writing the plist file below will fail.
QDir plistDir = QFileInfo(QString::fromNSString(plistFile)).dir();
if (!plistDir.exists()) {
if (!QDir().mkpath(plistDir.path())) {
return QString(QStringLiteral("Failed to create directory '%1'")).arg(plistDir.path());
}

// Permissions always seem to be 0700, so set that.
// Note: the Permission enum documentation states that on unix the owner permissions are
// returned, but: "This behavior might change in a future Qt version." So we play it safe,
// and set both the user and the owner permissions to rwx.
if (!QFile(plistDir.path()).setPermissions(QFileDevice::ReadOwner | QFileDevice::ReadUser | QFileDevice::WriteOwner | QFileDevice::WriteUser | QFileDevice::ExeOwner | QFileDevice::ExeUser)) {
qCInfo(lcUtility()) << "Failed to set directory permmissions for" << plistDir.path();
}
}

// Now write the file.
if (![plist writeToURL:[NSURL fileURLWithPath:plistFile isDirectory:NO] error:&error]) {
return QString::fromNSString(error.localizedDescription);
}
Expand Down

0 comments on commit 0a23565

Please sign in to comment.