mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Add testing writability as part of SUInstallerLauncher
This is necessary for detecting if automatic updates are possible in a sandboxed environment
This commit is contained in:
1 parent
5c08e0a1d1
commit
e7f85bb40f
10 files changed
+129
-36
No files matched your search
@@ -11,5 +11,5 @@
|
||||
|
||||
// Non-sandboxed XPC service used for launching our installer
|
||||
// This is necessary for sandboxed applications
|
||||
@interface SUInstallerLauncher : NSObject <InstallerLauncherProtocol>
|
||||
@interface SUInstallerLauncher : NSObject <SUInstallerLauncherProtocol>
|
||||
@end
|
||||
@@ -35,4 +35,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)testWritabilityAtPath:(NSString *)path completion:(void (^)(BOOL isWritable))completionHandler
|
||||
{
|
||||
completionHandler([[NSFileManager defaultManager] isWritableFileAtPath:path]);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// InstallerLauncherProtocol.h
|
||||
// SUInstallerLauncherProtocol.h
|
||||
// InstallerLauncher
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
@@ -8,8 +8,10 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol InstallerLauncherProtocol
|
||||
@protocol SUInstallerLauncherProtocol
|
||||
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath withArguments:(NSArray *)arguments completion:(void (^)(BOOL success))completionHandler;
|
||||
|
||||
- (void)testWritabilityAtPath:(NSString *)path completion:(void (^)(BOOL isWritable))completionHandler;
|
||||
|
||||
@end
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
// Configure the connection.
|
||||
// First, set the interface that the exported object implements.
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(InstallerLauncherProtocol)];
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
|
||||
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
|
||||
SUInstallerLauncher *exportedObject = [SUInstallerLauncher new];
|
||||
|
||||
@@ -174,6 +174,8 @@
|
||||
726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
|
||||
726E07C01CAF15B7001A286B /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; };
|
||||
726E07C21CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */; };
|
||||
726E07E91CAF30C0001A286B /* SUUpdaterPermission.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */; };
|
||||
726E07EA1CAF30C0001A286B /* SUUpdaterPermission.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */; };
|
||||
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E4A1A1C86C88F00C57C6A /* TestAppHelper.m */; };
|
||||
@@ -710,6 +712,8 @@
|
||||
726E07B31CAF08D6001A286B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
726E07B51CAF08D6001A286B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigInstallerLauncher.xcconfig; sourceTree = "<group>"; };
|
||||
726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterPermission.h; sourceTree = "<group>"; };
|
||||
726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterPermission.m; sourceTree = "<group>"; };
|
||||
726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = "<group>"; };
|
||||
726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = "<group>"; };
|
||||
726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = "<group>"; };
|
||||
@@ -1269,6 +1273,8 @@
|
||||
61CFB2C20E38496B007A1735 /* Drivers */,
|
||||
61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */,
|
||||
61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */,
|
||||
726E07E71CAF30C0001A286B /* SUUpdaterPermission.h */,
|
||||
726E07E81CAF30C0001A286B /* SUUpdaterPermission.m */,
|
||||
726E078B1CA891E9001A286B /* SUUpdaterSettings.h */,
|
||||
726E078C1CA891E9001A286B /* SUUpdaterSettings.m */,
|
||||
72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */,
|
||||
@@ -1440,6 +1446,7 @@
|
||||
726E07601CA4E9A5001A286B /* SUInstallationInputData.h in Headers */,
|
||||
725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */,
|
||||
767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */,
|
||||
726E07E91CAF30C0001A286B /* SUUpdaterPermission.h in Headers */,
|
||||
618FA5010DAE88B40026945C /* SUInstaller.h in Headers */,
|
||||
55C14F06136EF6DB00649790 /* SULog.h in Headers */,
|
||||
726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */,
|
||||
@@ -2070,6 +2077,7 @@
|
||||
729746411C9119F300FC134E /* SULocalMessagePort.m in Sources */,
|
||||
726E07611CA4E9A5001A286B /* SUInstallationInputData.m in Sources */,
|
||||
7275F9C21B5F1F2900B1D19E /* SUFileManager.m in Sources */,
|
||||
726E07EA1CAF30C0001A286B /* SUUpdaterPermission.m in Sources */,
|
||||
725CB95B1C7121830064365A /* SUStandardUserDriver.m in Sources */,
|
||||
61EF67560E25B58D00F754E0 /* SUHost.m in Sources */,
|
||||
55C14F07136EF6DB00649790 /* SULog.m in Sources */,
|
||||
|
||||
Vendored
+1
-1
@@ -388,7 +388,7 @@
|
||||
}
|
||||
|
||||
NSXPCConnection *launcherConnection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.InstallerLauncher"];
|
||||
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(InstallerLauncherProtocol)];
|
||||
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
[launcherConnection resume];
|
||||
|
||||
[launcherConnection.remoteObjectProxy launchInstallerAtPath:relaunchToolPath withArguments:@[hostBundleIdentifier] completion:^(BOOL success) {
|
||||
|
||||
Vendored
-2
@@ -67,8 +67,6 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
|
||||
@property (nonatomic) BOOL sendsSystemProfile;
|
||||
|
||||
@property (nonatomic, readonly) BOOL allowsAutomaticUpdates;
|
||||
|
||||
@property (nonatomic) BOOL automaticallyDownloadsUpdates;
|
||||
|
||||
/*!
|
||||
|
||||
Vendored
+43
-29
@@ -23,6 +23,7 @@
|
||||
#import "SUAutomaticUpdateDriver.h"
|
||||
#import "SUProbeInstallStatus.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUUpdaterPermission.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -43,6 +44,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
@property (strong) id <SUUpdateDriver> driver;
|
||||
@property (strong) SUHost *host;
|
||||
@property (nonatomic, readonly) SUUpdaterSettings *updaterSettings;
|
||||
@property (nonatomic, readonly) SUUpdaterPermission *updaterPermission;
|
||||
|
||||
@end
|
||||
|
||||
@@ -55,6 +57,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
@synthesize driver;
|
||||
@synthesize host;
|
||||
@synthesize updaterSettings = _updaterSettings;
|
||||
@synthesize updaterPermission = _updaterPermission;
|
||||
@synthesize sparkleBundle;
|
||||
|
||||
- (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id <SUUserDriver>)userDriver delegate:(id <SUUpdaterDelegate>)theDelegate
|
||||
@@ -72,6 +75,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
host = [[SUHost alloc] initWithBundle:bundle];
|
||||
|
||||
_updaterSettings = [[SUUpdaterSettings alloc] initWithHostBundle:bundle];
|
||||
_updaterPermission = [[SUUpdaterPermission alloc] init];
|
||||
|
||||
_userDriver = userDriver;
|
||||
|
||||
@@ -300,31 +304,33 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id
|
||||
// Wouldn't want to annoy users on dial-up by establishing a connection every
|
||||
// hour or so:
|
||||
|
||||
id <SUUpdateDriver> updateDriver;
|
||||
if ([self automaticallyDownloadsUpdates] && [self allowsAutomaticUpdates] && ![SUProbeInstallStatus probeInstallerInProgressForHost:self.host]) {
|
||||
updateDriver =
|
||||
[[SUAutomaticUpdateDriver alloc]
|
||||
initWithHost:self.host
|
||||
sparkleBundle:self.sparkleBundle
|
||||
updater:self
|
||||
updaterDelegate:self.delegate];
|
||||
} else {
|
||||
updateDriver =
|
||||
[[SUScheduledUpdateDriver alloc]
|
||||
initWithHost:self.host
|
||||
allowsAutomaticUpdates:[self allowsAutomaticUpdates]
|
||||
sparkleBundle:self.sparkleBundle
|
||||
updater:self
|
||||
userDriver:self.userDriver
|
||||
updaterDelegate:self.delegate];
|
||||
}
|
||||
|
||||
// We don't want the reachability check to act on the driver if the updater is going near death
|
||||
__weak SUUpdater *updater = self;
|
||||
NSURL *feedURL = [updater feedURL];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
SUCheckForUpdatesInBgReachabilityCheck(updater, updateDriver, feedURL);
|
||||
});
|
||||
[self allowsAutomaticUpdatesWithCompletion:^(BOOL allowsAutomaticUpdates) {
|
||||
id <SUUpdateDriver> updateDriver;
|
||||
if ([self automaticallyDownloadsUpdates] && allowsAutomaticUpdates && ![SUProbeInstallStatus probeInstallerInProgressForHost:self.host]) {
|
||||
updateDriver =
|
||||
[[SUAutomaticUpdateDriver alloc]
|
||||
initWithHost:self.host
|
||||
sparkleBundle:self.sparkleBundle
|
||||
updater:self
|
||||
updaterDelegate:self.delegate];
|
||||
} else {
|
||||
updateDriver =
|
||||
[[SUScheduledUpdateDriver alloc]
|
||||
initWithHost:self.host
|
||||
allowsAutomaticUpdates:allowsAutomaticUpdates
|
||||
sparkleBundle:self.sparkleBundle
|
||||
updater:self
|
||||
userDriver:self.userDriver
|
||||
updaterDelegate:self.delegate];
|
||||
}
|
||||
|
||||
// We don't want the reachability check to act on the driver if the updater is going near death
|
||||
__weak SUUpdater *updater = self;
|
||||
NSURL *feedURL = [updater feedURL];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
SUCheckForUpdatesInBgReachabilityCheck(updater, updateDriver, feedURL);
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)checkForUpdates
|
||||
@@ -335,8 +341,10 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id
|
||||
return;
|
||||
}
|
||||
|
||||
id <SUUpdateDriver> theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithHost:self.host allowsAutomaticUpdates:[self allowsAutomaticUpdates] sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate];
|
||||
[self checkForUpdatesWithDriver:theUpdateDriver];
|
||||
[self allowsAutomaticUpdatesWithCompletion:^(BOOL allowsAutomaticUpdates) {
|
||||
id <SUUpdateDriver> theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithHost:self.host allowsAutomaticUpdates:allowsAutomaticUpdates sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate];
|
||||
[self checkForUpdatesWithDriver:theUpdateDriver];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)checkForUpdateInformation
|
||||
@@ -443,10 +451,16 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id
|
||||
return [self.updaterSettings automaticallyDownloadsUpdates];
|
||||
}
|
||||
|
||||
- (BOOL)allowsAutomaticUpdates
|
||||
- (void)allowsAutomaticUpdatesWithCompletion:(void (^)(BOOL))completionHandler
|
||||
{
|
||||
NSNumber *developerAllowsAutomaticUpdates = [self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey];
|
||||
return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue) && [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath];
|
||||
if (developerAllowsAutomaticUpdates != nil && !developerAllowsAutomaticUpdates.boolValue) {
|
||||
completionHandler(NO);
|
||||
} else {
|
||||
[self.updaterPermission testUpdateWritabilityAtPath:self.host.bundlePath completion:^(BOOL isWritable) {
|
||||
completionHandler(isWritable);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFeedURL:(NSURL *)feedURL
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SUUpdaterPermission.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUUpdaterPermission : NSObject
|
||||
|
||||
// Must be called from main queue
|
||||
- (void)testUpdateWritabilityAtPath:(NSString *)path completion:(void (^)(BOOL))completionHandler;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// SUUpdaterPermission.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdaterPermission.h"
|
||||
#import "SUInstallerLauncherProtocol.h"
|
||||
|
||||
@interface SUUpdaterPermission ()
|
||||
|
||||
@property (nonatomic) BOOL allowsPermission;
|
||||
@property (nonatomic) BOOL checkedPermission;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUpdaterPermission
|
||||
|
||||
@synthesize allowsPermission = _allowsPermission;
|
||||
@synthesize checkedPermission = _checkedPermission;
|
||||
|
||||
- (void)testUpdateWritabilityAtPath:(NSString *)path completion:(void (^)(BOOL))completionHandler
|
||||
{
|
||||
if (!self.checkedPermission) {
|
||||
NSXPCConnection *launcherConnection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.InstallerLauncher"];
|
||||
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
[launcherConnection resume];
|
||||
|
||||
__weak SUUpdaterPermission *weakSelf = self;
|
||||
[launcherConnection.remoteObjectProxy testWritabilityAtPath:path completion:^(BOOL isWritable) {
|
||||
[launcherConnection invalidate];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
weakSelf.checkedPermission = YES;
|
||||
weakSelf.allowsPermission = isWritable;
|
||||
completionHandler(isWritable);
|
||||
});
|
||||
}];
|
||||
} else {
|
||||
completionHandler(self.allowsPermission);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user