mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Move appCachePath out of SUHost for process independence
The behavior depends on what kind of process is invoking is, which is no good.
This commit is contained in:
1 parent
fb32c8e18a
commit
301f3bf4e3
7 files changed
+45
-32
No files matched your search
Vendored
+31
-2
@@ -12,6 +12,7 @@
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUInstallerDriver.h"
|
||||
#import "SUDownloadDriver.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -44,13 +45,41 @@
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize userAgent = _userAgent;
|
||||
|
||||
// If we support sandboxing this component in the future, it is important to note this may return a different path
|
||||
// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from
|
||||
+ (NSString *)sparkleCachePathForHost:(SUHost *)host
|
||||
{
|
||||
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cachePath = nil;
|
||||
if ([cachePaths count]) {
|
||||
cachePath = [cachePaths objectAtIndex:0];
|
||||
}
|
||||
if (!cachePath) {
|
||||
SULog(@"Failed to find user's cache directory! Using system default");
|
||||
cachePath = NSTemporaryDirectory();
|
||||
}
|
||||
|
||||
NSString *name = [host.bundle bundleIdentifier];
|
||||
if (!name) {
|
||||
name = [host name];
|
||||
}
|
||||
|
||||
cachePath = [cachePath stringByAppendingPathComponent:name];
|
||||
cachePath = [cachePath stringByAppendingPathComponent:@"Sparkle"];
|
||||
return cachePath;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUCoreBasedUpdateDriverDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_delegate = delegate;
|
||||
|
||||
NSString *cachePath = [[self class] sparkleCachePathForHost:host];
|
||||
|
||||
_basicDriver = [[SUBasicUpdateDriver alloc] initWithHost:host updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
_installerDriver = [[SUInstallerDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
_installerDriver = [[SUInstallerDriver alloc] initWithHost:host cachePath:cachePath sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
|
||||
_host = host;
|
||||
_updater = updater;
|
||||
_updaterDelegate = updaterDelegate;
|
||||
@@ -86,7 +115,7 @@
|
||||
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem
|
||||
{
|
||||
self.downloadDriver = [[SUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host userAgent:self.userAgent delegate:self];
|
||||
self.downloadDriver = [[SUDownloadDriver alloc] initWithUpdateItem:updateItem host:self.host cachePath:[[self class] sparkleCachePathForHost:self.host] userAgent:self.userAgent delegate:self];
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) {
|
||||
[self.updaterDelegate updater:self.updater
|
||||
|
||||
Vendored
+1
-1
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUDownloadDriver : NSObject
|
||||
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate;
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host cachePath:(NSString *)cachePath userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate;
|
||||
|
||||
- (void)downloadUpdate;
|
||||
|
||||
|
||||
Vendored
+5
-2
@@ -21,6 +21,7 @@
|
||||
|
||||
@property (nonatomic, readonly) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly, copy) NSString *cachePath;
|
||||
@property (nonatomic) NSURLDownload *download;
|
||||
@property (nonatomic, copy) NSString *temporaryDirectory;
|
||||
@property (nonatomic, copy) NSString *downloadPath;
|
||||
@@ -33,17 +34,19 @@
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize request = _request;
|
||||
@synthesize host = _host;
|
||||
@synthesize cachePath = _cachePath;
|
||||
@synthesize download = _download;
|
||||
@synthesize temporaryDirectory = _temporaryDirectory;
|
||||
@synthesize downloadPath = _downloadPath;
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host cachePath:(NSString *)cachePath userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_updateItem = updateItem;
|
||||
_host = host;
|
||||
_cachePath = [cachePath copy];
|
||||
_delegate = delegate;
|
||||
|
||||
_request = [NSMutableURLRequest requestWithURL:updateItem.fileURL];
|
||||
@@ -94,7 +97,7 @@
|
||||
{
|
||||
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]];
|
||||
|
||||
NSString *cachePath = [self.host appCachePath];
|
||||
NSString *cachePath = self.cachePath;
|
||||
NSString *tempDir = [cachePath stringByAppendingPathComponent:downloadFileName];
|
||||
int count = 1;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && count <= 999)
|
||||
|
||||
Vendored
-1
@@ -15,7 +15,6 @@
|
||||
@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;
|
||||
@property (readonly, copy) NSString *name;
|
||||
@property (readonly, copy) NSString *version;
|
||||
|
||||
Vendored
+2
-23
@@ -20,7 +20,8 @@
|
||||
|
||||
// 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
|
||||
// as that may depend on the privileges of the process owner. Or code that depends on
|
||||
// if the process is sandboxed or not; eg: finding user caches directory
|
||||
|
||||
@interface SUHost ()
|
||||
|
||||
@@ -74,28 +75,6 @@
|
||||
return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue);
|
||||
}
|
||||
|
||||
- (NSString *)appCachePath
|
||||
{
|
||||
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cachePath = nil;
|
||||
if ([cachePaths count]) {
|
||||
cachePath = [cachePaths objectAtIndex:0];
|
||||
}
|
||||
if (!cachePath) {
|
||||
SULog(@"Failed to find user's cache directory! Using system default");
|
||||
cachePath = NSTemporaryDirectory();
|
||||
}
|
||||
|
||||
NSString *name = [self.bundle bundleIdentifier];
|
||||
if (!name) {
|
||||
name = [self name];
|
||||
}
|
||||
|
||||
cachePath = [cachePath stringByAppendingPathComponent:name];
|
||||
cachePath = [cachePath stringByAppendingPathComponent:@"Sparkle"];
|
||||
return cachePath;
|
||||
}
|
||||
|
||||
- (NSString *)installationPath
|
||||
{
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
|
||||
Vendored
+1
-1
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUInstallerDriver : NSObject
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate;
|
||||
- (instancetype)initWithHost:(SUHost *)host cachePath:(NSString *)cachePath sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate;
|
||||
|
||||
- (BOOL)extractDownloadPath:(NSString *)downloadPath withUpdateItem:(SUAppcastItem *)updateItem temporaryDirectory:(NSString *)temporaryDirectory error:(NSError * __autoreleasing *)error;
|
||||
|
||||
|
||||
Vendored
+5
-2
@@ -28,6 +28,7 @@
|
||||
@interface SUInstallerDriver ()
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly, copy) NSString *cachePath;
|
||||
@property (nonatomic, readonly) NSBundle *sparkleBundle;
|
||||
@property (nonatomic, weak, readonly) id<SUInstallerDriverDelegate> delegate;
|
||||
@property (nonatomic) SUInstallerMessageType currentStage;
|
||||
@@ -46,6 +47,7 @@
|
||||
@implementation SUInstallerDriver
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize cachePath = _cachePath;
|
||||
@synthesize sparkleBundle = _sparkleBundle;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize currentStage = _currentStage;
|
||||
@@ -58,11 +60,12 @@
|
||||
@synthesize downloadPath = _downloadPath;
|
||||
@synthesize temporaryDirectory = _temporaryDirectory;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate
|
||||
- (instancetype)initWithHost:(SUHost *)host cachePath:(NSString *)cachePath sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_host = host;
|
||||
_cachePath = [cachePath copy];
|
||||
_sparkleBundle = sparkleBundle;
|
||||
_updater = updater;
|
||||
_updaterDelegate = updaterDelegate;
|
||||
@@ -330,7 +333,7 @@
|
||||
NSString *const relaunchToolName = @"" SPARKLE_RELAUNCH_TOOL_NAME;
|
||||
NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"];
|
||||
if (relaunchPathToCopy != nil) {
|
||||
NSString *targetPath = [self.host.appCachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
NSString *targetPath = [self.cachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
|
||||
SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO];
|
||||
NSError *error = nil;
|
||||
|
||||
Reference in new issue
Block a user