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.
This commit is contained in:
Zorg committed 2015-04-04 13:29:29 -04:00
1 parent 729087f696
commit 44b027a178
1 file changed
+15 -2
+15 -2
View File
@@ -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);