From 4973c0143f66e9f5c4f864eb2ab56d21ebd76d8f Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 29 Apr 2018 13:33:53 +0100 Subject: [PATCH] Whitespace --- Sparkle/SUFileManager.m | 58 +++++++++++++++++++------------------- Sparkle/SUPlainInstaller.m | 40 +++++++++++++------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 7bf08747..15e3be7e 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -109,20 +109,20 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { _auth = NULL; return NO; } - + AuthorizationItem rightItems[] = { // The right that allows us to run tools as root user {.name = kAuthorizationRightExecute, .valueLength = 0, .value = NULL, .flags = 0} }; - + AuthorizationRights rights = { .count = sizeof(rightItems) / sizeof(*rightItems), .items = rightItems }; - + AuthorizationFlags flags = (AuthorizationFlags)(kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize); - + // This will test if we can gain authorization for running utlities as root OSStatus copyStatus = AuthorizationCopyRights(_auth, &rights, kAuthorizationEmptyEnvironment, flags, NULL); if (copyStatus != errAuthorizationSuccess) { @@ -133,13 +133,13 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed granting authorization rights with status code %d.", copyStatus] }]; } } - + AuthorizationFree(_auth, kAuthorizationFlagDefaults); _auth = NULL; - + return NO; } - + return YES; } @@ -156,9 +156,9 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char *arguments[] = { command, sourcePath, destinationPath, NULL }; - + char toolPath[PATH_MAX] = {0}; if (![_authorizationToolPath getFileSystemRepresentation:toolPath maxLength:sizeof(toolPath)]) { if (error != NULL) { @@ -166,7 +166,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + FILE *pipe = NULL; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" @@ -181,7 +181,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + uint32_t pidData = 0; if (fread(&pidData, sizeof(pidData), 1, pipe) < 1) { if (error != NULL) { @@ -190,7 +190,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { fclose(pipe); return NO; } - + if (lineCallback) { NSFileHandle *pipeHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(pipe) closeOnDealloc:NO]; [self parseLines:pipeHandle lineCallback:lineCallback]; @@ -198,21 +198,21 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { pid_t childPid = (int32_t)CFSwapInt32LittleToHost(pidData); int status = 0; - + pid_t waitResult; do { waitResult = waitpid(childPid, &status, 0); } while (waitResult == -1 && errno == EINTR); - + fclose(pipe); - + if (waitResult == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (error != NULL) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Failed to execute authorized executable with result %d and status (%d, %d, %d).", waitResult, status, WIFEXITED(status), WEXITSTATUS(status)] }]; } return NO; } - + return YES; } @@ -624,7 +624,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; if (![self _authorizeAndExecuteCommand:SUFileOpMoveCommand sourcePath:sourcePath destinationPath:destinationPath error:&executeError]) { if (error != NULL) { @@ -654,11 +654,11 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + // We use fchown instead of chown because the latter can follow symbolic links BOOL success = fchown(fileDescriptor, ownerID.unsignedIntValue, groupID.unsignedIntValue) == 0; close(fileDescriptor); - + if (!success) { if (errno == EPERM) { if (needsAuth != NULL) { @@ -769,7 +769,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char matchPath[PATH_MAX] = {0}; if (![matchURLPath getFileSystemRepresentation:matchPath maxLength:sizeof(matchPath)]) { if (error != NULL) { @@ -818,12 +818,12 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + // Using futimes() because utimes() follows symbolic links BOOL updatedTime = (futimes(fileDescriptor, NULL) == 0); - + close(fileDescriptor); - + if (updatedTime) { return YES; } @@ -884,7 +884,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpMakeDirectoryCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success) { @@ -893,7 +893,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage, NSUnderlyingErrorKey: executeError }]; } } - + return success; } @@ -946,14 +946,14 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpRemoveCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success && error != NULL) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to remove %@ with authentication.", url.path.lastPathComponent], NSUnderlyingErrorKey: executeError }]; } - + return success; } @@ -966,7 +966,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char path[PATH_MAX] = {0}; if (![packageURL.path getFileSystemRepresentation:path maxLength:sizeof(path)]) { if (error != NULL) { @@ -981,7 +981,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { progressBlock([[line substringFromIndex:11] doubleValue]/100.0); } } error:&executeError]; - + if (!success && error != NULL) { NSString* errorMessage = @"Failed to execute package installer."; *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: errorMessage, NSUnderlyingErrorKey: executeError}]; diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index a7fd0281..1c781634 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -50,14 +50,14 @@ { NSString *bundleVersion = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; NSString *trimmedVersion = @""; - + if (bundleVersion != nil) { NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet]; [validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]]; - + trimmedVersion = [bundleVersion stringByTrimmingCharactersInSet:[validCharacters invertedSet]]; } - + return trimmedVersion.length > 0 ? trimmedVersion : nil; } @@ -77,7 +77,7 @@ } SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:fileOperationToolPath]; - + // Create a temporary directory for our new app that resides on our destination's volume NSString *preferredName = [installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"]; NSURL *installationDirectory = installationURL.URLByDeletingLastPathComponent; @@ -107,7 +107,7 @@ // 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 - + NSError *quarantineError = nil; if (![fileManager releaseItemFromQuarantineAtRootURL:newTempURL error:&quarantineError]) { // Not big enough of a deal to fail the entire installation @@ -127,14 +127,14 @@ } return NO; } - + if (![fileManager changeOwnerAndGroupOfItemAtRootURL:newTempURL toMatchURL:oldURL error:error]) { // But this is big enough of a deal to fail SULog(SULogLevelError, @"Failed to change owner and group of new app at %@ to match old app at %@", newTempURL.path, oldURL.path); [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; return NO; } - + if (progress) { progress(5/10.0); } @@ -152,16 +152,16 @@ NSString *oldDestinationName = nil; if (SPARKLE_APPEND_VERSION_NUMBER) { NSString *oldBundleVersion = [self bundleVersionAppropriateForFilenameFromHost:host]; - + oldDestinationName = [oldURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingFormat:@" (%@)", oldBundleVersion != nil ? oldBundleVersion : @"old"]; } else { oldDestinationName = oldURL.lastPathComponent.stringByDeletingPathExtension; } - + NSString *oldURLExtension = oldURL.pathExtension; NSString *oldDestinationNameWithPathExtension = [oldDestinationName stringByAppendingPathExtension:oldURLExtension]; NSURL *oldURLDirectory = oldURL.URLByDeletingLastPathComponent; - + // Create a temporary directory for our old app that resides on its volume NSURL *tempOldDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:oldDestinationName appropriateForDirectoryURL:oldURLDirectory error:error]; if (tempOldDirectoryURL == nil) { @@ -178,11 +178,11 @@ NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldDestinationNameWithPathExtension]; if (![fileManager moveItemAtURL:oldURL toURL:oldTempURL error:error]) { SULog(SULogLevelError, @"Failed to move the old app at %@ to a temporary location at %@", oldURL.path, oldTempURL.path); - + // Just forget about our updated app on failure [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; [fileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; - + return NO; } @@ -193,14 +193,14 @@ // Move the new app to its final destination if (![fileManager moveItemAtURL:newTempURL toURL:installationURL error:error]) { SULog(SULogLevelError, @"Failed to move new app at %@ to final destination %@", newTempURL.path, installationURL.path); - + // Forget about our updated app on failure [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; - + // Attempt to restore our old app back the way it was on failure [fileManager moveItemAtURL:oldTempURL toURL:oldURL error:NULL]; [fileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; - + return NO; } @@ -210,7 +210,7 @@ // From here on out, we don't really need to bring up authorization if we haven't done so prior SUFileManager *constrainedFileManager = [fileManager fileManagerByPreservingAuthorizationRights]; - + // Cleanup [constrainedFileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; [constrainedFileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; @@ -225,20 +225,20 @@ - (BOOL)performInitialInstallation:(NSError * __autoreleasing *)error { BOOL allowDowngrades = SPARKLE_AUTOMATED_DOWNGRADES; - + // Prevent malicious downgrades if (!allowDowngrades) { NSString *hostVersion = [self.host version]; - + NSBundle *bundle = [NSBundle bundleWithPath:self.bundlePath]; SUHost *updateHost = [[SUHost alloc] initWithBundle:bundle]; NSString *updateVersion = [updateHost objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; - + id comparator = [[SUStandardVersionComparator alloc] init]; if (!updateVersion || [comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) { if (error != NULL) { NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", hostVersion, updateVersion]; - + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; } return NO;