From 641f3b0d4758ed354f255f7a46b73b359b8fd84d Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 1 Jul 2016 21:23:51 -0400 Subject: [PATCH] Update mdimporter bundles during delta extraction During delta extraction, these bundles may not be updated appropriately, so we should just be safe and update them ourselves --- Sparkle/SUBinaryDeltaUnarchiver.m | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index 0263d0c2..9e71a3b7 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -10,6 +10,7 @@ #import "SUBinaryDeltaCommon.h" #import "SUBinaryDeltaApply.h" #import "SULog.h" +#import "SUFileManager.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -54,7 +55,42 @@ NSError *applyDiffError = nil; BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, &applyDiffError); + if (success) { + // 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 because it doesn't work under root user, + // and 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 + + 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); + } + } + } + dispatch_async(dispatch_get_main_queue(), ^{ [self.delegate unarchiverDidFinish]; });