Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Try to unquarantine the host app before checking for updates. #183

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Squirrel/SQRLUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2013 GitHub. All rights reserved.
//

#import <sys/xattr.h>
#import "SQRLUpdater.h"
#import "NSBundle+SQRLVersionExtensions.h"
#import "NSError+SQRLVerbosityExtensions.h"
Expand Down Expand Up @@ -53,6 +54,10 @@ @interface SQRLUpdater ()
// Sends completed or error.
@property (nonatomic, strong, readonly) RACSignal *shipItLauncher;

/// Was the app quarantined when we tried checking for updates? Will be nil if
/// we haven't checked yet.
@property (atomic, copy) NSNumber *wasQuarantined;

// Parses an update model from downloaded data.
//
// data - JSON data representing an update manifest. This must not be nil.
Expand Down Expand Up @@ -171,9 +176,16 @@ - (id)initWithUpdateRequest:(NSURLRequest *)updateRequest {
NSMutableURLRequest *request = [self.updateRequest mutableCopy];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

return [[[[[[[[self
return [[[[[[[[[self
performHousekeeping]
then:^{
return [self unquarantineApp];
}]
flattenMap:^(NSNumber *quarantined) {
// If we were quarantined then we can't check for updates until
// the app is relaunched.
if (quarantined.boolValue) return [RACSignal empty];

self.state = SQRLUpdaterStateCheckingForUpdate;

return [NSURLConnection rac_sendAsynchronousRequest:request];
Expand Down Expand Up @@ -240,6 +252,21 @@ - (id)initWithUpdateRequest:(NSURLRequest *)updateRequest {

#pragma mark Checking for Updates

- (RACSignal *)unquarantineApp {
return [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) {
if (self.wasQuarantined == nil) {
NSURL *targetURL = NSRunningApplication.currentApplication.bundleURL;
const char *path = targetURL.path.fileSystemRepresentation;
int result = removexattr(path, "com.apple.quarantine", XATTR_NOFOLLOW);
self.wasQuarantined = @(result == 0);
}

[subscriber sendNext:self.wasQuarantined];
[subscriber sendCompleted];
return nil;
}];
}

- (RACDisposable *)startAutomaticChecksWithInterval:(NSTimeInterval)interval {
@weakify(self);

Expand Down