Updater on OS X: Only allow if in /Applications #2931
authorMarkus Goetz <markus@woboq.com>
Tue, 5 May 2015 16:48:57 +0000 (18:48 +0200)
committerMarkus Goetz <markus@woboq.com>
Thu, 7 May 2015 11:04:25 +0000 (13:04 +0200)
src/gui/updater/sparkleupdater_mac.mm

index 038275eba89fc04119443f8f43b0c3789b916a2b..74079f0f760ca44512d65e13e048328bef60a8fa 100644 (file)
@@ -111,15 +111,33 @@ SparkleUpdater::~SparkleUpdater()
     delete d;
 }
 
+
+bool autoUpdaterAllowed()
+{
+    // See https://github.com/owncloud/client/issues/2931
+    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
+    NSString *expectedPath = [NSString stringWithFormat:@"/Applications/%@", [bundlePath lastPathComponent]];
+    if ([expectedPath isEqualTo:bundlePath]) {
+        return true;
+    }
+    qWarning() << "ERROR: We are not in /Applications, won't check for update!";
+    return false;
+}
+
+
 void SparkleUpdater::checkForUpdate()
 {
-    [d->updater checkForUpdates: NSApp];
+    if (autoUpdaterAllowed()) {
+        [d->updater checkForUpdates: NSApp];
+    }
 }
 
 void SparkleUpdater::backgroundCheckForUpdate()
 {
     qDebug() << Q_FUNC_INFO << "launching background check";
-    [d->updater checkForUpdatesInBackground];
+    if (autoUpdaterAllowed()) {
+        [d->updater checkForUpdatesInBackground];
+    }
 }
 
 } // namespace OCC