From 44b027a17867a3e08f0d11b8846d416d9cf786fb Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 4 Apr 2015 13:29:29 -0400 Subject: [PATCH 1/2] Fix BinaryDelta sometimes failing when a dir becomes a dir link This can occur in the following case: -- original_tree: A/ Current/ B new_tree: A/ B Current -> A/ -- Because symbolic links are not followed, Current/B can be marked as deleted. If A/B is added before the deletion, then A will end up as an empty directory. Our fix is to remove all subpaths of a file when it changes from a directory to another type of file. This should also decrease the size of the diff even in harmless cases such as when a directory changes into a regular file. --- Sparkle/SUBinaryDeltaTool.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index bede8ba7..a7039fe1 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -206,10 +206,23 @@ int main(int __unused argc, char __unused *argv[]) NSDictionary *info = infoForFile(ent); NSDictionary *oldInfo = originalTreeState[key]; - if ([info isEqual:oldInfo]) + if ([info isEqual:oldInfo]) { [newTreeState removeObjectForKey:key]; - else + } else { newTreeState[key] = info; + + if (oldInfo && [oldInfo[@"type"] unsignedShortValue] == FTS_D && [info[@"type"] unsignedShortValue] != FTS_D) { + NSArray *pathComponents = key.pathComponents; + + for (NSString *subpath in originalTreeState) { + NSArray *subpathComponents = subpath.pathComponents; + if (subpathComponents.count > pathComponents.count && + [pathComponents isEqualToArray:[subpathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count)]]) { + [newTreeState removeObjectForKey:subpath]; + } + } + } + } } fts_close(fts); From 5589a604b81cdb5adc822b1dca50578d501f431f Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 4 Apr 2015 16:44:36 -0400 Subject: [PATCH 2/2] Use child/parent names with paths for better clarity --- Sparkle/SUBinaryDeltaTool.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index a7039fe1..81b80b28 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -212,13 +212,13 @@ int main(int __unused argc, char __unused *argv[]) newTreeState[key] = info; if (oldInfo && [oldInfo[@"type"] unsignedShortValue] == FTS_D && [info[@"type"] unsignedShortValue] != FTS_D) { - NSArray *pathComponents = key.pathComponents; + NSArray *parentPathComponents = key.pathComponents; - for (NSString *subpath in originalTreeState) { - NSArray *subpathComponents = subpath.pathComponents; - if (subpathComponents.count > pathComponents.count && - [pathComponents isEqualToArray:[subpathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count)]]) { - [newTreeState removeObjectForKey:subpath]; + for (NSString *childPath in originalTreeState) { + NSArray *childPathComponents = childPath.pathComponents; + if (childPathComponents.count > parentPathComponents.count && + [parentPathComponents isEqualToArray:[childPathComponents subarrayWithRange:NSMakeRange(0, parentPathComponents.count)]]) { + [newTreeState removeObjectForKey:childPath]; } } }