From 2dfc8494d70b3ccbc064be59bd981b5a59223060 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 3 Apr 2015 17:45:43 -0400 Subject: [PATCH] Fix BinaryDelta failing on filenames changing case When a filename changes case, make sure we have the file deleted in the old tree before being extracted into the new one. Note that we don't try creating a diff if a file is renamed with a different case, just like we don't track file names changing in other ways. See issue #474 --- Sparkle/SUBinaryDeltaTool.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index bede8ba7..474cb964 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -227,7 +227,16 @@ int main(int __unused argc, char __unused *argv[]) NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init]; NSMutableArray *deltaOperations = [NSMutableArray array]; - NSArray *keys = [[newTreeState allKeys] sortedArrayUsingSelector:@selector(compare:)]; + // Sort the keys by preferring the ones from the original tree to appear first + // We want to enforce deleting before extracting in the case paths differ only by case + NSArray *keys = [[newTreeState allKeys] sortedArrayUsingComparator:^NSComparisonResult(NSString *key1, NSString *key2) { + NSComparisonResult insensitiveCompareResult = [key1 caseInsensitiveCompare:key2]; + if (insensitiveCompareResult != NSOrderedSame) { + return insensitiveCompareResult; + } + + return originalTreeState[key1] ? NSOrderedAscending : NSOrderedDescending; + }]; for (NSString* key in keys) { id value = [newTreeState valueForKey:key];