From 779d16e5a7f27399c4c838ee4b6a71cd37ddfbc4 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 15:27:11 -0400 Subject: [PATCH] Update spotlight bundles after delta extraction; don't use mdimport --- Sparkle/SUBinaryDeltaUnarchiver.m | 38 +++++++++++++++++++++++++++++++ Sparkle/SUInstaller.m | 23 +------------------ 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index e9990e65..bfba873d 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -10,6 +10,7 @@ #import "SUBinaryDeltaUnarchiver.h" #import "SUBinaryDeltaApply.h" #import "SUUnarchiver_Private.h" +#import "SUFileManager.h" #import "SUHost.h" #import "SULog.h" @@ -20,6 +21,41 @@ return [[path pathExtension] isEqualToString:@"delta"]; } +// According to https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/MDImporters/Concepts/Troubleshooting.html +// We should make sure mdimporter bundles have an up to date time in the event they were delta updated. +// We used to invoke mdimport on the bundle but this is not a very good approach. +// There's no need to do that for non-delta updates and for updates that contain no mdimporters. +// Moreover, updating the timestamp on the mdimporter bundles is what developers have to do anyway when shipping their new update outside of Sparkle +- (void)updateSpotlightImportersAtBundlePath:(NSString *)targetPath +{ + NSURL *targetURL = [NSURL fileURLWithPath:targetPath]; + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary *rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:targetPath error:nil]; + NSString *rootType = [rootAttributes objectForKey:NSFileType]; + + if ([rootType isEqualToString:NSFileTypeDirectory]) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; + + NSMutableArray *filesToUpdate = [[NSMutableArray alloc] init]; + for (NSURL *file in directoryEnumerator) { + if ([file.pathExtension isEqualToString:@"mdimporter"]) { + [filesToUpdate addObject:file]; + } + } + + SUFileManager *fileManager = [SUFileManager defaultManager]; + for (NSURL *file in filesToUpdate) { + NSError *error = nil; + if (![fileManager updateModificationAndAccessTimeOfItemAtURL:file error:&error]) { + SULog(@"Error: During delta unarchiving, failed to touch %@", error); + } + } + } +} + - (void)applyBinaryDelta { @autoreleasepool { @@ -29,6 +65,8 @@ NSError *applyDiffError = nil; BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, &applyDiffError); if (success) { + [self updateSpotlightImportersAtBundlePath:targetPath]; + dispatch_async(dispatch_get_main_queue(), ^{ [self notifyDelegateOfSuccess]; }); diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 45919ea3..c96ffadd 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -122,30 +122,9 @@ } } -+ (void)mdimportInstallationPath:(NSString *)installationPath -{ - // *** GETS CALLED ON NON-MAIN THREAD! - - SULog(@"mdimporting"); - - NSTask *mdimport = [[NSTask alloc] init]; - [mdimport setLaunchPath:@"/usr/bin/mdimport"]; - [mdimport setArguments:@[installationPath]]; - @try { - [mdimport launch]; - [mdimport waitUntilExit]; - } - @catch (NSException *launchException) - { - // No big deal. - SULog(@"Error: %@", [launchException description]); - } -} - -+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler ++ (void)finishInstallationToPath:(NSString *)__unused installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler { if (result) { - [self mdimportInstallationPath:installationPath]; dispatch_async(dispatch_get_main_queue(), ^{ completionHandler(nil); });