From 9e9fef0d5146bd3edadda6629a06bef8152bb13c Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 18 Apr 2015 17:59:52 -0400 Subject: [PATCH] Add an extract property for creating/applying binary diffs Before, an extract was assumed if nothing else matched. This can get quite confusing when adding new properties, so we shouldn't treat any property to be handled if nothing else was handled. --- Sparkle/SUBinaryDeltaApply.m | 12 ++++++++---- Sparkle/SUBinaryDeltaCommon.h | 3 ++- Sparkle/SUBinaryDeltaCreate.m | 10 +++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Sparkle/SUBinaryDeltaApply.m b/Sparkle/SUBinaryDeltaApply.m index d318464b..8d2a522d 100644 --- a/Sparkle/SUBinaryDeltaApply.m +++ b/Sparkle/SUBinaryDeltaApply.m @@ -120,6 +120,8 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil fprintf(stderr, "Failed to copy %s to %s\n", [source fileSystemRepresentation], [destination fileSystemRepresentation]); return 1; } + + BOOL hasExtractKeyAvailable = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion); fprintf(stdout, "\nPatching... "); xar_file_t file; @@ -130,12 +132,13 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil NSString *destinationFilePath = [destination stringByAppendingPathComponent:path]; const char *value; - if (!xar_prop_get(file, DELETE_KEY, &value) || !xar_prop_get(file, DELETE_THEN_EXTRACT_KEY, &value)) { + if (!xar_prop_get(file, DELETE_KEY, &value) || + (!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_THEN_EXTRACT_OLD_KEY, &value))) { if (!removeTree(destinationFilePath)) { - fprintf(stderr, "%s or %s: failed to remove %s\n", DELETE_KEY, DELETE_THEN_EXTRACT_KEY, [destination fileSystemRepresentation]); + fprintf(stderr, "%s or %s: failed to remove %s\n", DELETE_KEY, DELETE_THEN_EXTRACT_OLD_KEY, [destination fileSystemRepresentation]); return 1; } - if (!xar_prop_get(file, DELETE_KEY, &value)) + if (!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_KEY, &value)) continue; } @@ -144,7 +147,8 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil fprintf(stderr, "Unable to patch %s to destination %s\n", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation]); return 1; } - } else if (xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value)) { + } else if ((hasExtractKeyAvailable && !xar_prop_get(file, EXTRACT_KEY, &value)) || + (!hasExtractKeyAvailable && xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value))) { // extract and permission modifications don't coexist if (xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]) != 0) { fprintf(stderr, "Unable to extract file to %s\n", [destinationFilePath fileSystemRepresentation]); return 1; diff --git a/Sparkle/SUBinaryDeltaCommon.h b/Sparkle/SUBinaryDeltaCommon.h index 4f008f55..803dbc3d 100644 --- a/Sparkle/SUBinaryDeltaCommon.h +++ b/Sparkle/SUBinaryDeltaCommon.h @@ -22,11 +22,12 @@ #define BEFORE_TREE_SHA1_KEY "before-tree-sha1" #define AFTER_TREE_SHA1_KEY "after-tree-sha1" #define DELETE_KEY "delete" -#define DELETE_THEN_EXTRACT_KEY "delete-then-extract" +#define EXTRACT_KEY "extract" #define BINARY_DELTA_KEY "binary-delta" #define MODIFY_PERMISSIONS_KEY "mod-permissions" // Properties no longer used in new patches +#define DELETE_THEN_EXTRACT_OLD_KEY "delete-then-extract" #define BEFORE_TREE_SHA1_OLD_KEY "before-sha1" #define AFTER_TREE_SHA1_OLD_KEY "after-sha1" diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index 17de119a..d1b6756d 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -371,7 +371,15 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi assert(newFile); if (shouldDeleteThenExtract(originalInfo, newInfo)) { - xar_prop_set(newFile, DELETE_THEN_EXTRACT_KEY, "true"); + if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) { + xar_prop_set(newFile, DELETE_KEY, "true"); + } else { + xar_prop_set(newFile, DELETE_THEN_EXTRACT_OLD_KEY, "true"); + } + } + + if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) { + xar_prop_set(newFile, EXTRACT_KEY, "true"); } } } else {