Move permission checking of allowing automatic updates to SUUpdater

SUHost can be called from any process with different privilege levels,
so it can't determine if the user can install to the app bundle without issue
This commit is contained in:
Zorg committed 2016-02-29 22:48:27 -05:00
1 parent f7b6a70979
commit b6fe5ea289
9 files changed
+31 -18

No files matched your search

+1
View File
@@ -13,6 +13,7 @@
- (instancetype)initWithBundle:(NSBundle *)aBundle;
@property (readonly, copy) NSString *bundlePath;
// Even if automatic updates are allowed, this does not indicate that the user has writable permissions to do so conveniently
@property (readonly) BOOL allowsAutomaticUpdates;
@property (readonly, copy) NSString *appCachePath;
@property (readonly, copy) NSString *installationPath;
+7 -7
View File
@@ -18,6 +18,10 @@
#error This is a "core" class and should NOT import AppKit
#endif
// This class should also be process independent
// For example, it should not have code that tests writabilty to somewhere on disk,
// as that may depend on the privileges of the process owner
@interface SUHost ()
@property (strong, readwrite) NSBundle *bundle;
@@ -62,16 +66,12 @@
return [self.bundle bundlePath];
}
// We can't determine whether or not the updater has sufficient privilleges to install automatic updates without interrupting the user
// To find that out, ask the SUUpdater which has responsibility for that
- (BOOL)allowsAutomaticUpdates
{
// Does the developer want us to disable automatic updates?
NSNumber *developerAllowsAutomaticUpdates = [self objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey];
if (developerAllowsAutomaticUpdates != nil && !developerAllowsAutomaticUpdates.boolValue) {
return NO;
}
// Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)?
return [[NSFileManager defaultManager] isWritableFileAtPath:self.bundlePath];
return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue);
}
- (NSString *)appCachePath
+2 -2
View File
@@ -200,11 +200,11 @@
#pragma mark Update Found
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)versionDisplayer allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates reply:(void (^)(SUUpdateAlertChoice))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
__weak SUSparkleUserUpdaterDriver *weakSelf = self;
SUUpdateAlert *updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
SUUpdateAlert *updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host allowsAutomaticUpdates:allowsAutomaticUpdates completionBlock:^(SUUpdateAlertChoice choice) {
reply(choice);
weakSelf.activeUpdateAlert = nil;
}];
+1 -1
View File
@@ -44,7 +44,7 @@
versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater];
}
[self.updater.userUpdaterDriver showUpdateFoundWithAppcastItem:self.updateItem versionDisplayer:versDisp reply:^(SUUpdateAlertChoice choice) {
[self.updater.userUpdaterDriver showUpdateFoundWithAppcastItem:self.updateItem versionDisplayer:versDisp allowsAutomaticUpdates:self.updater.allowsAutomaticUpdates reply:^(SUUpdateAlertChoice choice) {
dispatch_async(dispatch_get_main_queue(), ^{
[self updateAlertFinishedWithChoice:choice];
});
+1 -1
View File
@@ -20,7 +20,7 @@
@property (weak) id<SUVersionDisplay> versionDisplayer;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates completionBlock:(void(^)(SUUpdateAlertChoice))c;
- (IBAction)installUpdate:sender;
- (IBAction)skipThisVersion:sender;
+4 -6
View File
@@ -34,6 +34,7 @@
@property (strong) SUAppcastItem *updateItem;
@property (strong) SUHost *host;
@property (nonatomic) BOOL allowsAutomaticUpdates;
@property (strong) void(^completionBlock)(SUUpdateAlertChoice);
@property (strong) NSProgressIndicator *releaseNotesSpinner;
@@ -56,6 +57,7 @@
@synthesize updateItem;
@synthesize host;
@synthesize allowsAutomaticUpdates = _allowsAutomaticUpdates;
@synthesize releaseNotesSpinner;
@synthesize webViewFinishedLoading;
@@ -68,7 +70,7 @@
@synthesize skipButton;
@synthesize laterButton;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates completionBlock:(void (^)(SUUpdateAlertChoice))block
{
self = [super initWithWindowNibName:@"SUUpdateAlert"];
if (self)
@@ -76,6 +78,7 @@
self.completionBlock = block;
host = aHost;
updateItem = item;
_allowsAutomaticUpdates = allowsAutomaticUpdates;
[self setShouldCascadeWindows:NO];
// Alex: This dummy line makes sure that the binary is linked against WebKit.
@@ -170,11 +173,6 @@
return [shouldShowReleaseNotes boolValue];
}
- (BOOL)allowsAutomaticUpdates
{
return self.host.allowsAutomaticUpdates;
}
- (void)windowDidLoad
{
BOOL showReleaseNotes = [self showsReleaseNotes];
+12
View File
@@ -401,11 +401,23 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, SU
if (!self.host.allowsAutomaticUpdates) {
return NO;
}
// Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)?
if (![[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath]) {
return NO;
}
// Otherwise, automatically downloading updates is allowed. Does the user want it?
return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
}
- (BOOL)allowsAutomaticUpdates
{
// Make sure the host allows automatic updates and
// make sure we can automatically update in the background without bugging the user (e.g, with a administrator password prompt)
return (self.host.allowsAutomaticUpdates && [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath]);
}
- (void)setFeedURL:(NSURL *)feedURL
{
if (![NSThread isMainThread])
+2
View File
@@ -12,4 +12,6 @@
@property (readonly) BOOL mayUpdateAndRestart;
@property (readonly, nonatomic) BOOL allowsAutomaticUpdates;
@end
+1 -1
View File
@@ -27,7 +27,7 @@
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SUUserInitiatedCheckStatus))updateCheckStatusCompletion;
- (void)dismissUserInitiatedUpdateCheck;
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply;
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)versionDisplayer allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates reply:(void (^)(SUUpdateAlertChoice))reply;
#warning maybe this should take a versionDisplayer too?
- (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply;