From da370c0f2b276c10f473f2879501e24537b4ebe9 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Sun, 27 Sep 2015 12:24:47 -0700 Subject: [PATCH 1/3] Avoid converting URLs to paths to check for existence --- TestApplication/SUTestApplicationDelegate.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index 09e98c71..d62353c6 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -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]; From 079666643dfbef582c9818a390815d030552d006 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Sun, 27 Sep 2015 12:31:45 -0700 Subject: [PATCH 2/3] Set the task working directories instead of changing the process working directory --- TestApplication/SUTestApplicationDelegate.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index d62353c6..481222d2 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -92,14 +92,15 @@ 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]; @@ -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([[NSFileManager defaultManager] 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]; From 2ad01ad672c18e88f7289a7c21cc5fba26e20090 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Sun, 27 Sep 2015 12:33:14 -0700 Subject: [PATCH 3/3] Reuse file manager variable --- TestApplication/SUTestApplicationDelegate.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index 481222d2..b46a739a 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -106,7 +106,7 @@ static NSString * const UPDATED_VERSION = @"2.0"; 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) @@ -178,7 +178,7 @@ static NSString * const UPDATED_VERSION = @"2.0"; // Finally start the server NSTask *serverTask = [[NSTask alloc] init]; serverTask.launchPath = @"/usr/bin/python"; - assert([[NSFileManager defaultManager] fileExistsAtPath:serverTask.launchPath]); + assert([fileManager fileExistsAtPath:serverTask.launchPath]); serverTask.arguments = @[@"-m", @"SimpleHTTPServer", @"1337"]; serverTask.currentDirectoryPath = serverDirectoryPath; [serverTask launch];