Compare commits

..
27 Commits
Author SHA1 Message Date
Kornel 545b8f2416 Merge pull request #653 from artillery/artillery-seamless2
Fire didFindValidUpdate even if automatically installing updates
2015-10-08 23:45:44 +01:00
Ian Langworth ☠ d1a62bba89 Fire didFindValidUpdate even if automatically installing updates 2015-10-08 15:33:00 -07:00
Kornel Lesiński 7ccf706a1d Synthesize automaticallyInstallUpdates 2015-10-08 23:25:21 +01:00
Kornel ef61691b34 Merge pull request #620 from artillery/artillery-seamless
Add automatically-install-updates option
2015-10-08 23:17:21 +01:00
Ian Langworth ☠ a92c23bb26 Add automatically install updates option 2015-10-08 14:45:05 -07:00
Kornel abc307dc35 Merge pull request #647 from kainjow/patch-1
Fix readme headings
2015-10-05 11:10:02 +01:00
Kevin Wojniak 49e262e718 Fix readme headings 2015-10-04 16:36:57 -07:00
Jake Petroules 25be040bfc Merge pull request #643 from sparkle-project/maxcdn
MaxCDN
2015-10-03 05:56:59 -07:00
Kornel 46c677ea57 Merge pull request #641 from sparkle-project/charconv
Char conversions
2015-09-30 19:00:16 +01:00
Kornel Lesiński 165b772f8f MaxCDN 2015-09-29 00:39:35 +01:00
Kornel Lesiński bac2463ff2 Use a C formatting function for a C string 2015-09-28 10:54:30 +01:00
Kornel Lesiński c61b5d99a2 Avoid conversion from NSString to char[] 2015-09-28 10:46:36 +01:00
Jake Petroules e54498dd35 Merge pull request #640 from sparkle-project/fix-warnings
Fix warnings.
2015-09-27 16:21:28 -07:00
Jake Petroules 9ca70a5157 Fix warnings. 2015-09-27 16:16:37 -07:00
Jake Petroules f9b9184a39 Merge pull request #639 from sparkle-project/at-least-version
Use proper version checking.
2015-09-27 16:00:32 -07:00
Jake Petroules b943af3b59 Use proper version checking. 2015-09-27 15:55:26 -07:00
Jake Petroules 5afdc4f20e Implement isOperatingSystemAtLeastVersion: 2015-09-27 15:41:23 -07:00
Kornel f85ac88595 Merge pull request #635 from zorgiepoo/update-mod-time
Update modification & access time for new update
2015-09-27 23:02:29 +01:00
Zorg e9e04e2cb4 Merge branch 'master' into update-mod-time 2015-09-27 17:05:07 -04:00
Jake Petroules 114252dd09 Merge pull request #637 from kainjow/test-app-urls
Test app cleanup
2015-09-27 13:35:31 -07:00
Zorg 2f41dec805 Log any installation error that may occur 2015-09-27 16:19:35 -04:00
Kevin Wojniak 2ad01ad672 Reuse file manager variable 2015-09-27 12:33:14 -07:00
Kevin Wojniak 079666643d Set the task working directories instead of changing the process working directory 2015-09-27 12:31:45 -07:00
Kevin Wojniak da370c0f2b Avoid converting URLs to paths to check for existence 2015-09-27 12:24:47 -07:00
Zorg b98026040f Merge branch 'master' into update-mod-time 2015-09-27 11:19:36 -04:00
Zorg 83578c1f38 Merge branch 'master' into update-mod-time 2015-09-27 11:05:22 -04:00
Zorg 6af2fbfb6e Update modification & access time for new update
If we don't do this, Finder may not report the correct file size for the new update.
The system also may not register the new app in its database if we don't do this.

We may have been able to get away with not doing this before because we used to perform a copy
to install the update. However, now updates in some cases can be done with only move operations.

This should also be an alternative way of addressing issue #508
2015-09-27 10:53:22 -04:00
16 changed files with 206 additions and 64 deletions

No files matched your search

+8 -3
View File
@@ -1,4 +1,4 @@
# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) <a href='https://app.ship.io/dashboard#/jobs/8814/history' target='_blank'><img src='https://app.ship.io/jobs/V3PoCLcN5ft5Pnq0/build_status.png' height='20' /></a> [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master)
# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) <a href='https://app.ship.io/dashboard#/jobs/8814/history' target='_blank'><img src='https://app.ship.io/jobs/V3PoCLcN5ft5Pnq0/build_status.png' height='20' /></a> [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) <a href="https://www.bandwidthhog.com/?utm_source=sparkle-github&amp;utm_medium=badge&amp;utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-Bandwidth%20Hog-orange.svg" alt="sponsored by: bandwidth hog"></a>
An easy-to-use software update framework for Cocoa developers.
@@ -36,13 +36,18 @@ An easy-to-use software update framework for Cocoa developers.
* Runtime: OS X 10.7 or greater
* Build: Xcode 5 and 10.8 SDK or greater
### API
## API
Sparkle is built with `-fvisibility=hidden -fvisibility-inlines-hidden` which means no symbols are exported by default.
If you are adding a symbol to the public API you must decorate the declaration with the `SU_EXPORT` macro (grep the source code for examples).
### Building the distribution package
## Building the distribution package
`cd` to the root of the Sparkle source tree and run `make release`. Sparkle-*VERSION*.tar.bz2 will be created in a temporary directory and revealed in Finder after the build has completed.
Alternatively, build the Distribution scheme in the Xcode UI.
## Project Sponsor
[Bandwidth Hog](https://www.bandwidthhog.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer) is a service from MaxCDN
that allows you to push software updates to your customers for only 1¢ a gigabyte. Best part is there are no contracts, it is all Pay-as-you-Go.
+1
View File
@@ -172,6 +172,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
versionComparator:[SUStandardVersionComparator defaultComparator]
completionHandler:^(NSError *error) {
if (error) {
SULog(@"Installation Error: %@", error);
if (self.shouldShowUI) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"";
+13
View File
@@ -79,6 +79,19 @@
*/
- (BOOL)changeOwnerAndGroupOfItemAtRootURL:(NSURL *)targetURL toMatchURL:(NSURL *)matchURL error:(NSError **)error;
/**
* Updates the modification and access time of an item at a specified target URL to the current time
* @param targetURL A URL pointing to the target item whose modification and access time to update. The item at this URL must exist.
* @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
* @return YES if the target item's modification and access times have been updated, otherwise NO along with a populated error object
*
* This method updates the modification and access time of an item to the current time, ideal for letting the system know we installed a new file or
* application.
*
* This is not an atomic operation.
*/
- (BOOL)updateModificationAndAccessTimeOfItemAtURL:(NSURL *)targetURL error:(NSError **)error;
/**
* Releases Apple's quarantine extended attribute from the item at the specified root URL
* @param rootURL A URL pointing to the item to release from Apple's quarantine. This will be applied recursively if the item is a directory. The item at this URL must exist.
+61 -39
View File
@@ -7,15 +7,13 @@
//
#import "SUFileManager.h"
#import "SUHost.h"
#include <sys/xattr.h>
#include <sys/errno.h>
#include <sys/time.h>
#pragma clang diagnostic push
// This is a private constant but it's referenced from our unit tests
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
NSString *SUAppleQuarantineIdentifier = @"com.apple.quarantine";
#pragma clang diagnostic pop
static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine";
// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan!
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char *executablePath, AuthorizationFlags options, char *const *arguments)
@@ -122,7 +120,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
}
// Wrapper around getxattr()
- (ssize_t)_getXAttr:(NSString *)nameString fromFile:(NSString *)file options:(int)options
- (ssize_t)_getXAttr:(const char *)name fromFile:(NSString *)file options:(int)options
{
char path[PATH_MAX] = {0};
if (![file getFileSystemRepresentation:path maxLength:sizeof(path)]) {
@@ -130,17 +128,11 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
return -1;
}
const char *name = [nameString cStringUsingEncoding:NSASCIIStringEncoding];
if (name == NULL) {
errno = 0;
return -1;
}
return getxattr(path, name, NULL, 0, 0, options);
}
// Wrapper around removexattr()
- (int)_removeXAttr:(NSString *)name fromFile:(NSString *)file options:(int)options
- (int)_removeXAttr:(const char *)attr fromFile:(NSString *)file options:(int)options
{
char path[PATH_MAX] = {0};
if (![file getFileSystemRepresentation:path maxLength:sizeof(path)]) {
@@ -148,18 +140,12 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
return -1;
}
const char *attr = [name cStringUsingEncoding:NSASCIIStringEncoding];
if (attr == NULL) {
errno = 0;
return -1;
}
return removexattr(path, attr, options);
}
#define XATTR_UTILITY_PATH "/usr/bin/xattr"
// Recursively remove an xattr at a specified root URL with authentication
- (BOOL)_removeXAttrWithAuthentication:(NSString *)name fromRootURL:(NSURL *)rootURL error:(NSError *__autoreleasing *)error
- (BOOL)_removeXAttrWithAuthentication:(char *__nonnull)xattrName fromRootURL:(NSURL *)rootURL error:(NSError *__autoreleasing *)error
{
// Because this is a system utility, it's fine to follow the symbolic link if one exists
if (![_fileManager fileExistsAtPath:@(XATTR_UTILITY_PATH)]) {
@@ -177,22 +163,14 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
return NO;
}
const char *xattrName = [name cStringUsingEncoding:NSASCIIStringEncoding];
if (xattrName == NULL) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteInapplicableStringEncodingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Extended attribute %@ is not a valid ASCII convertible string.", name] }];
}
return NO;
}
if (![self _acquireAuthorizationWithError:error]) {
return NO;
}
BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, XATTR_UTILITY_PATH, kAuthorizationFlagDefaults, (char *[]){ "-s", "-r", "-d", (char *)xattrName, path, NULL });
BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, XATTR_UTILITY_PATH, kAuthorizationFlagDefaults, (char *[]){ "-s", "-r", "-d", xattrName, path, NULL });
if (!success && error != NULL) {
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated extended attribute deletion for %@ failed on %@.", name, rootURL.path.lastPathComponent];
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated extended attribute deletion for %@ failed on %@.", [NSString stringWithUTF8String:xattrName], rootURL.path.lastPathComponent];
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey:errorMessage }];
}
@@ -505,11 +483,55 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
return NO;
}
NSString *formattedUserAndGroupIDs = [NSString stringWithFormat:@"%u:%u", ownerID.unsignedIntValue, groupID.unsignedIntValue];
const char *userAndGroup = [formattedUserAndGroupIDs cStringUsingEncoding:NSASCIIStringEncoding];
if (userAndGroup == NULL) {
char userAndGroup[100];
int written = snprintf(userAndGroup, sizeof(userAndGroup), "%u:%u", ownerID.unsignedIntValue, groupID.unsignedIntValue);
if (written < 0 || written >= 100) {
return NO; // No custom error, because it's too unlikely to ever happen
}
if (![self _acquireAuthorizationWithError:error]) {
return NO;
}
BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char *[]){ "-R", userAndGroup, targetPath, NULL });
if (!success && error != NULL) {
NSString *errorMessage = [NSString stringWithFormat:@"Failed to change owner:group %@ on %@ with authentication.", [NSString stringWithUTF8String:userAndGroup], targetURL.path.lastPathComponent];
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
}
return success;
}
// /usr/bin/touch can be used to update an application, as described in:
// https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html
// The document says LSRegisterURL() can be used as well but this hasn't worked out well for me in practice
// Anyway, updating the modification time of the application is important because the system will be aware a new version of your app is available,
// Finder will report the correct file size and other metadata for it, URL schemes your app may register will be updated, etc.
// Behind the scenes, touch calls to utimes() which is what we use here - unless we need to authenticate
- (BOOL)updateModificationAndAccessTimeOfItemAtURL:(NSURL *)targetURL error:(NSError * __autoreleasing *)error
{
if (![self _itemExistsAtURL:targetURL]) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFormattingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Owner ID %u and Group ID %u could not be formatted.", ownerID.unsignedIntValue, groupID.unsignedIntValue] }];
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileNoSuchFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to update modification & access time because %@ does not exist.", targetURL.path.lastPathComponent] }];
}
return NO;
}
char path[PATH_MAX] = {0};
if (![targetURL.path getFileSystemRepresentation:path maxLength:sizeof(path)]) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"File to update modification & access time (%@) cannot be represented as a valid file name.", targetURL.path.lastPathComponent] }];
}
return NO;
}
if (utimes(path, NULL) == 0) {
return YES;
}
if (errno != EACCES) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to update modification & access time for %@", targetURL.path.lastPathComponent] }];
}
return NO;
}
@@ -518,9 +540,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
return NO;
}
BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char *[]){ "-R", (char *)userAndGroup, targetPath, NULL });
BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, "/usr/bin/touch", kAuthorizationFlagDefaults, (char *[]){ path, NULL });
if (!success && error != NULL) {
NSString *errorMessage = [NSString stringWithFormat:@"Failed to change owner:group %@ on %@ with authentication.", formattedUserAndGroupIDs, targetURL.path.lastPathComponent];
NSString *errorMessage = [NSString stringWithFormat:@"Failed to update modification & access time on %@ with authentication.", targetURL.path.lastPathComponent];
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
}
@@ -651,8 +673,8 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
NSURL *trashURL = nil;
BOOL canUseNewTrashAPI = YES;
#if __MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
canUseNewTrashAPI = [_fileManager respondsToSelector:@selector(trashItemAtURL:resultingItemURL:error:)];
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
canUseNewTrashAPI = [SUHost isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}];
if (!canUseNewTrashAPI) {
FSRef trashRef;
if (FSFindFolder(kUserDomain, kTrashFolderType, kDontCreateFolder, &trashRef) == noErr) {
@@ -699,7 +721,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
// If we get here, we should be able to trash the item normally without authentication
BOOL success = NO;
#if __MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
if (!canUseNewTrashAPI) {
NSString *tempParentPath = tempItemURL.URLByDeletingLastPathComponent.path;
success = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:tempParentPath destination:@"" files:@[tempItemURL.lastPathComponent] tag:NULL];
+1
View File
@@ -24,6 +24,7 @@ typedef struct {
@property (strong, readonly) NSBundle *bundle;
+ (NSOperatingSystemVersion)operatingSystemVersion;
+ (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version;
+ (NSString *)systemVersionString;
- (instancetype)initWithBundle:(NSBundle *)aBundle;
+13 -1
View File
@@ -286,7 +286,7 @@
+ (NSOperatingSystemVersion)operatingSystemVersion
{
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090 // Present in 10.9 despite NS_AVAILABLE's claims
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wselector"
// Xcode 5.1.1: operatingSystemVersion is clearly declared, must warn due to a compiler bug?
@@ -305,6 +305,18 @@
return [[NSProcessInfo processInfo] operatingSystemVersion];
}
+ (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version
{
const NSOperatingSystemVersion systemVersion = self.operatingSystemVersion;
if (systemVersion.majorVersion == version.majorVersion) {
if (systemVersion.minorVersion == version.minorVersion) {
return systemVersion.patchVersion >= version.patchVersion;
}
return systemVersion.minorVersion >= version.minorVersion;
}
return systemVersion.majorVersion >= version.majorVersion;
}
+ (NSString *)systemVersionString
{
NSOperatingSystemVersion version = self.operatingSystemVersion;
+6 -1
View File
@@ -60,7 +60,7 @@
return NO;
}
// Release our new app from quarantine and fix its owner and group IDs while it's at our temporary destination
// Release our new app from quarantine, fix its owner and group IDs, and update its modification time while it's at our temporary destination
// We must leave moving the app to its destination as the final step in installing it, so that
// it's not possible our new app can be left in an incomplete state at the final destination
@@ -87,6 +87,11 @@
return NO;
}
if (![fileManager updateModificationAndAccessTimeOfItemAtURL:newTempURL error:error]) {
// Not a fatal error, but a pretty unfortunate one
SULog(@"Failed to update modification and access time of new app at %@", newTempURL.path);
}
// Decide on a destination name we should use for the older app when we move it around the file system
NSString *oldDestinationName = nil;
if (SPARKLE_APPEND_VERSION_NUMBER) {
+36 -12
View File
@@ -41,8 +41,25 @@
@synthesize statusController;
@synthesize updateAlert;
- (instancetype)initWithUpdater:(SUUpdater *)anUpdater
{
if ((self = [super initWithUpdater:anUpdater])) {
self.automaticallyInstallUpdates = NO;
}
return self;
}
- (void)didFindValidUpdate
{
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
}
if (self.automaticallyInstallUpdates) {
[self updateAlertFinishedWithChoice:SUInstallUpdateChoice];
return;
}
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
[self updateAlertFinishedWithChoice:choice];
}];
@@ -53,10 +70,6 @@
}
[self.updateAlert setVersionDisplayer:versDisp];
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
}
// If the app is a menubar app or the like, we need to focus it first and alter the
// update prompt to behave like a normal window. Otherwise if the window were hidden
// there may be no way for the application to be activated to make it visible again.
@@ -78,12 +91,14 @@
[[self.updater delegate] updaterDidNotFindUpdate:self.updater];
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
[alert addButtonWithTitle:SULocalizedString(@"OK", nil)];
[self showModalAlert:alert];
[self abortUpdate];
if (!self.automaticallyInstallUpdates) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
[alert addButtonWithTitle:SULocalizedString(@"OK", nil)];
[self showModalAlert:alert];
[self abortUpdate];
}
}
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
@@ -128,7 +143,7 @@
- (NSString *)localizedStringFromByteCount:(long long)value
{
if (SUHost.operatingSystemVersion.minorVersion < 8) {
if (![SUHost isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}]) {
if (value < 1000) {
return [NSString stringWithFormat:@"%.0lf %@", value / 1.0,
SULocalizedString(@"B", @"the unit for bytes")];
@@ -163,8 +178,12 @@
- (IBAction)cancelDownload:(id)__unused sender
{
if (self.download)
if (self.download) {
[self.download cancel];
if ([[self.updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) {
[[self.updater delegate] userDidCancelDownload:self.updater];
}
}
[self abortUpdate];
}
@@ -187,6 +206,11 @@
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
{
if (self.automaticallyInstallUpdates) {
[self installWithToolAndRelaunch:YES];
return;
}
[self.statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil];
[self.statusController setProgressValue:1.0]; // Fill the bar.
[self.statusController setButtonEnabled:YES];
+1
View File
@@ -24,6 +24,7 @@ extern NSString *const SUUpdateDriverFinishedNotification;
- (void)abortUpdate;
@property (getter=isInterruptible, readonly) BOOL interruptible;
@property (readonly) BOOL finished;
@property BOOL automaticallyInstallUpdates;
@end
+1
View File
@@ -26,6 +26,7 @@ NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
@synthesize interruptible;
@synthesize finished;
@synthesize appcastURL;
@synthesize automaticallyInstallUpdates;
- (instancetype)initWithUpdater:(SUUpdater *)anUpdater
{
+17
View File
@@ -77,6 +77,16 @@ SU_EXPORT @interface SUUpdater : NSObject
*/
- (void)checkForUpdatesInBackground;
/*!
Checks for updates and, if available, immediately downloads and installs them.
A progress dialog is shown but the user will never be prompted to read the
release notes.
You may want to respond to the userDidCancelDownload delegate method in case
the user clicks the "Cancel" button while the update is downloading.
*/
- (void)installUpdatesIfAvailable;
/*!
Returns the date of last update check.
@@ -228,6 +238,13 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
*/
- (void)updater:(SUUpdater *)updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error;
/*!
Called when the user clicks the cancel button while and update is being downloaded.
\param updater The SUUpdater instance.
*/
- (void)userDidCancelDownload:(SUUpdater *)updater;
/*!
Called immediately before installing the specified update.
+11
View File
@@ -333,6 +333,17 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
[self checkForUpdatesWithDriver:[[SUProbingUpdateDriver alloc] initWithUpdater:self]];
}
- (void)installUpdatesIfAvailable
{
if (self.driver && [self.driver isInterruptible]) {
[self.driver abortUpdate];
}
SUUIBasedUpdateDriver *theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithUpdater:self];
theUpdateDriver.automaticallyInstallUpdates = YES;
[self checkForUpdatesWithDriver:theUpdateDriver];
}
- (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d
{
if ([self updateInProgress]) { return; }
+13 -6
View File
@@ -53,7 +53,7 @@ static NSString * const UPDATED_VERSION = @"2.0";
// Create a directory that'll be used for our web server listing
NSURL *serverDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier];
if ([fileManager fileExistsAtPath:serverDirectoryURL.path]) {
if ([serverDirectoryURL checkResourceIsReachableAndReturnError:nil]) {
NSError *removeServerDirectoryError = nil;
if (![fileManager removeItemAtURL:serverDirectoryURL error:&removeServerDirectoryError]) {
@@ -81,7 +81,7 @@ static NSString * const UPDATED_VERSION = @"2.0";
// Update bundle's version keys to latest version
NSURL *infoURL = [[destinationBundleURL URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"Info.plist"];
BOOL infoFileExists = [fileManager fileExistsAtPath:infoURL.path];
BOOL infoFileExists = [infoURL checkResourceIsReachableAndReturnError:nil];
assert(infoFileExists);
NSMutableDictionary *infoDictionary = [[NSMutableDictionary alloc] initWithContentsOfURL:infoURL];
@@ -92,20 +92,21 @@ static NSString * const UPDATED_VERSION = @"2.0";
assert(wroteInfoFile);
// Change current working directory so web server knows where to list files
BOOL changedCurrentWorkingDirectory = [fileManager changeCurrentDirectoryPath:serverDirectoryURL.path];
assert(changedCurrentWorkingDirectory);
NSString *serverDirectoryPath = serverDirectoryURL.path;
assert(serverDirectoryPath != nil);
// Create the archive for our update
NSString *zipName = @"Sparkle_Test_App.zip";
NSTask *dittoTask = [[NSTask alloc] init];
dittoTask.launchPath = @"/usr/bin/ditto";
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", destinationBundleURL.lastPathComponent, zipName];
dittoTask.currentDirectoryPath = serverDirectoryPath;
[dittoTask launch];
[dittoTask waitUntilExit];
assert(dittoTask.terminationStatus == 0);
[[NSFileManager defaultManager] removeItemAtURL:destinationBundleURL error:NULL];
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
// Don't ever do this at home, kids (seriously)
// (that is, including the private key inside of your application)
@@ -175,7 +176,13 @@ static NSString * const UPDATED_VERSION = @"2.0";
}
// Finally start the server
self.serverTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/python" arguments:@[@"-m", @"SimpleHTTPServer", @"1337"]];
NSTask *serverTask = [[NSTask alloc] init];
serverTask.launchPath = @"/usr/bin/python";
assert([fileManager fileExistsAtPath:serverTask.launchPath]);
serverTask.arguments = @[@"-m", @"SimpleHTTPServer", @"1337"];
serverTask.currentDirectoryPath = serverDirectoryPath;
[serverTask launch];
self.serverTask = serverTask;
// Show the Settings window
self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
+1 -1
View File
@@ -67,7 +67,7 @@
{
SUDSAVerifier *v = [[SUDSAVerifier alloc] initWithPublicKeyData:pubKey];
NSData *sig = [[NSData alloc] initWithBase64Encoding:sigString];
NSData *sig = [[NSData alloc] initWithBase64EncodedString:sigString options:(NSDataBase64DecodingOptions)0];
return [v verifyFileAtPath:aFile signature:sig];
}
+21
View File
@@ -169,6 +169,27 @@ class SUFileManagerTest: XCTestCase
}
}
func testUpdateFileModificationTime()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL in
XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItemAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
let oldOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
let oldDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
sleep(1); // wait for clock to advance
try! fileManager.updateModificationAndAccessTimeOfItemAtURL(ordinaryFileURL)
try! fileManager.updateModificationAndAccessTimeOfItemAtURL(directoryURL)
let newOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
XCTAssertGreaterThan((newOrdinaryFileAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldOrdinaryFileAttributes[NSFileModificationDate] as! NSDate), 0)
let newDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
XCTAssertGreaterThan((newDirectoryAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldDirectoryAttributes[NSFileModificationDate] as! NSDate), 0)
}
}
func testFileExists()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL in
+2 -1
View File
@@ -7,7 +7,8 @@
#import "SUBinaryDeltaCommon.h"
#import "SUFileManager.h"
extern NSString *SUAppleQuarantineIdentifier;
// Duplicated to avoid exporting a private symbol from SUFileManager
static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
@interface SUFileManager (Private)