From 3c957096c64de93c93c9c49e7ebd3bbe254ee2a8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 10 Oct 2015 17:42:27 -0400 Subject: [PATCH] Use class constructor instead of an init method for SUFileManager I think it's more natural this way --- Sparkle/SUBasicUpdateDriver.m | 2 +- Sparkle/SUFileManager.h | 6 +++--- Sparkle/SUFileManager.m | 8 +++++++- Sparkle/SUPlainInstaller.m | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 2b52ea8a..173ce204 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -452,7 +452,7 @@ if (relaunchPathToCopy != nil) { NSString *targetPath = [self.host.appCachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; - SUFileManager *fileManager = [[SUFileManager alloc] initAllowingAuthorization:NO]; + SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO]; NSError *error = nil; NSURL *relaunchURLToCopy = [NSURL fileURLWithPath:relaunchPathToCopy]; diff --git a/Sparkle/SUFileManager.h b/Sparkle/SUFileManager.h index 7dde8cab..f6897ced 100644 --- a/Sparkle/SUFileManager.h +++ b/Sparkle/SUFileManager.h @@ -16,14 +16,14 @@ @interface SUFileManager : NSObject /** - * Initializes a file manager + * Creates a file manager that allows or disallows authorizing for file operations * @param allowsAuthorization Specifies whether operations invoked on this instance are allowed to acquire authorization in order * to perform file operations when read or write access is denied * @return A new file manager instance * - * This method just initializes the file manager. It doesn't acquire authorization immediately if allowsAuthorization is YES + * This method just creates the file manager. It doesn't acquire authorization immediately if allowsAuthorization is YES */ -- (id)initAllowingAuthorization:(BOOL)allowsAuthorization; ++ (instancetype)fileManagerAllowingAuthorization:(BOOL)allowsAuthorization; /** * Creates a temporary directory on the same volume as a provided URL diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 243e0f5b..fa36a997 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -55,7 +55,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza BOOL _allowsAuthorization; } -- (id)initAllowingAuthorization:(BOOL)allowsAuthorization +- (instancetype)initAllowingAuthorization:(BOOL)allowsAuthorization { self = [super init]; if (self != nil) { @@ -65,6 +65,12 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return self; } + ++ (instancetype)fileManagerAllowingAuthorization:(BOOL)allowsAuthorization +{ + return [[self alloc] initAllowingAuthorization:allowsAuthorization]; +} + // Acquires an authorization reference which is intended to be used for future authorized file operations - (BOOL)_acquireAuthorizationWithError:(NSError *__autoreleasing *)error { diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index e6a922b7..70a7ded9 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -42,7 +42,7 @@ return NO; } - SUFileManager *fileManager = [[SUFileManager alloc] initAllowingAuthorization:YES]; + SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:YES]; // Create a temporary directory for our new app that resides on our destination's volume NSURL *tempNewDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:[installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"] appropriateForDirectoryURL:installationURL.URLByDeletingLastPathComponent error:error];