From 41f953d77ba00999bf3be21336264f94c8c09b96 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 8 Jan 2022 21:23:15 -0800 Subject: [PATCH] Fix minor binary delta issues and make version 3 the default (#2055) --- Autoupdate/SPUSparkleDeltaArchive.h | 2 +- Autoupdate/SPUSparkleDeltaArchive.m | 2 ++ Autoupdate/SUBinaryDeltaApply.m | 3 +++ Autoupdate/SUBinaryDeltaCommon.h | 2 +- Autoupdate/SUBinaryDeltaCommon.m | 2 +- Autoupdate/SUBinaryDeltaCreate.m | 28 ++++++++++++++-------------- Configurations/ConfigCommon.xcconfig | 2 +- generate_appcast/Appcast.swift | 7 ++----- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Autoupdate/SPUSparkleDeltaArchive.h b/Autoupdate/SPUSparkleDeltaArchive.h index 0288833a..735720ef 100644 --- a/Autoupdate/SPUSparkleDeltaArchive.h +++ b/Autoupdate/SPUSparkleDeltaArchive.h @@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN CLONE_FILE and EXTRACT_FILE cannot be combined. MODIFY_PERMISSIONS can be combined with either CLONE_FILE, EXTRACT_FILE, BINARY_DIFF_FILE, or just by itself. CLONE_FILE can be combined with BINARY_DIFF_FILE or just by itself. - DELETE can be combined with EXTRACT_FILE, BINARY_DIFF_FILE, or just by itself. (we don't currently combine it with BINARY_DIFF_FILE however) + DELETE can be combined with EXTRACT_FILE, or just by itself. It is only combined with EXTRACT_FILE when the file type (regular, directory, or symlink) changes. [ DATA_BLOBS ] All raw binary data joined together diff --git a/Autoupdate/SPUSparkleDeltaArchive.m b/Autoupdate/SPUSparkleDeltaArchive.m index c131af52..431973f3 100644 --- a/Autoupdate/SPUSparkleDeltaArchive.m +++ b/Autoupdate/SPUSparkleDeltaArchive.m @@ -623,6 +623,8 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod return NO; } + [fileManager removeItemAtPath:itemFilePath error:NULL]; + NSError *createLinkError = nil; if (![fileManager createSymbolicLinkAtPath:itemFilePath withDestinationPath:destinationPath error:&createLinkError]) { self.error = createLinkError; diff --git a/Autoupdate/SUBinaryDeltaApply.m b/Autoupdate/SUBinaryDeltaApply.m index 3aefb951..91c39102 100644 --- a/Autoupdate/SUBinaryDeltaApply.m +++ b/Autoupdate/SUBinaryDeltaApply.m @@ -219,6 +219,9 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi NSString *clonedOriginalPath = [source stringByAppendingPathComponent:clonedRelativePath]; + // Ensure there isn't an item already at our destination + [fileManager removeItemAtPath:destinationFilePath error:NULL]; + NSError *copyError = nil; if (![fileManager copyItemAtPath:clonedOriginalPath toPath:destinationFilePath error:©Error]) { if (verbose) { diff --git a/Autoupdate/SUBinaryDeltaCommon.h b/Autoupdate/SUBinaryDeltaCommon.h index 157d2ecd..0cd39f50 100644 --- a/Autoupdate/SUBinaryDeltaCommon.h +++ b/Autoupdate/SUBinaryDeltaCommon.h @@ -45,7 +45,7 @@ extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionLatest; extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst; extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported; -#define COMPRESSION_METHOD_ARGUMENT_DESCRIPTION @"The compression method to use for generating delta updates. Supported methods for version 3 delta files are 'lzma', 'bzip2', 'zlib', 'lzfse', 'lz4', 'none', and 'default'. Note that version 2 delta files only support 'bzip2', 'none', and 'default' so other methods will be ignored if version 2 files are being generated." +#define COMPRESSION_METHOD_ARGUMENT_DESCRIPTION @"The compression method to use for generating delta updates. Supported methods for version 3 delta files are 'lzma', 'bzip2', 'zlib', 'lzfse', 'lz4', 'none', and 'default'. Note that version 2 delta files only support 'bzip2', 'none', and 'default' so other methods will be ignored if version 2 files are being generated. The 'default' compression for version 3 delta files is currently lzma." #define COMPRESSION_LEVEL_ARGUMENT_DESCRIPTION @"The compression level to use for generating delta updates. This only applies if the compression method used is bzip2 which accepts values from 1 - 9. A special value of 0 will use the default compression level." diff --git a/Autoupdate/SUBinaryDeltaCommon.m b/Autoupdate/SUBinaryDeltaCommon.m index 3aae6e49..8d8fac11 100644 --- a/Autoupdate/SUBinaryDeltaCommon.m +++ b/Autoupdate/SUBinaryDeltaCommon.m @@ -21,7 +21,7 @@ // Note: the framework bundle version must be bumped, and generate_appcast must be updated to compare it, // when we add/change new major versions and defaults. Unit tests need to be updated to use new versions too. -SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault = SUBinaryDeltaMajorVersion2; +SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault = SUBinaryDeltaMajorVersion3; SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionLatest = SUBinaryDeltaMajorVersion3; SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst = SUBinaryDeltaMajorVersion1; SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported = SUBinaryDeltaMajorVersion2; diff --git a/Autoupdate/SUBinaryDeltaCreate.m b/Autoupdate/SUBinaryDeltaCreate.m index fcf58cc3..585562b1 100644 --- a/Autoupdate/SUBinaryDeltaCreate.m +++ b/Autoupdate/SUBinaryDeltaCreate.m @@ -195,7 +195,7 @@ static BOOL shouldSkipDeltaCompression(NSDictionary *originalInfo, NSDictionary return NO; } -static BOOL shouldDeleteThenExtract(NSDictionary *originalInfo, NSDictionary *newInfo, SUBinaryDeltaMajorVersion majorVersion) +static BOOL shouldDeleteThenExtract(NSDictionary *originalInfo, NSDictionary *newInfo) { if (!originalInfo) { return NO; @@ -204,14 +204,6 @@ static BOOL shouldDeleteThenExtract(NSDictionary *originalInfo, NSDictionary *ne if ([(NSNumber *)originalInfo[INFO_TYPE_KEY] unsignedShortValue] != [(NSNumber *)newInfo[INFO_TYPE_KEY] unsignedShortValue]) { return YES; } - - // If the same file exists in both old and new trees and they have different content, - // we should always issue deleting the old file before extracting the new - // I believe xar container in version 2 format automatically did this if the file types were the same - // but we don't want to rely on that implicitness - if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3)) { - return YES; - } return NO; } @@ -470,6 +462,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF } fts_close(fts); + // This dictionary will help us keep track of clones NSMutableDictionary *> *beforeHashToFileKeyDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil; unsigned char beforeHash[CC_SHA1_DIGEST_LENGTH] = {0}; @@ -559,7 +552,16 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF NSDictionary *oldInfo = originalTreeState[key]; - if ([info isEqual:oldInfo]) { + BOOL hasEqualInfo; + if (![info isEqual:oldInfo]) { + hasEqualInfo = NO; + } else { + NSString *originalPath = oldInfo[INFO_PATH_KEY]; + NSString *newPath = info[INFO_PATH_KEY]; + hasEqualInfo = [[NSFileManager defaultManager] contentsEqualAtPath:originalPath andPath:newPath]; + } + + if (hasEqualInfo) { [newTreeState removeObjectForKey:key]; } else { newTreeState[key] = info; @@ -579,6 +581,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF } fts_close(fts); + // This dictionary will help us keep track of clones NSMutableDictionary *afterFileKeyToHashDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil; unsigned char afterHash[CC_SHA1_DIGEST_LENGTH] = {0}; @@ -766,9 +769,6 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF [deltaOperations addObject:operation]; } else { SPUDeltaItemCommands commands = SPUDeltaItemCommandClone; - if (shouldDeleteThenExtract(originalInfo, newInfo, majorVersion)) { - commands |= SPUDeltaItemCommandDelete; - } if (clonePermissionsChanged) { commands |= SPUDeltaItemCommandModifyPermissions; } @@ -790,7 +790,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF NSString *path = [destination stringByAppendingPathComponent:key]; SPUDeltaItemCommands commands = SPUDeltaItemCommandExtract; - if (shouldDeleteThenExtract(originalInfo, newInfo, majorVersion)) { + if (shouldDeleteThenExtract(originalInfo, newInfo)) { commands |= SPUDeltaItemCommandDelete; } diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index e391abec..61d78bc2 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -40,7 +40,7 @@ SPARKLE_VERSION_PATCH = 0 // This should be in SemVer format or empty, ie. "-beta.1" // These variables must have a space after the '=' too SPARKLE_VERSION_SUFFIX = -CURRENT_PROJECT_VERSION = 2009 +CURRENT_PROJECT_VERSION = 2010 MARKETING_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)$(SPARKLE_VERSION_SUFFIX) ALWAYS_SEARCH_USER_PATHS = NO diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 76a70db0..25a497d0 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -111,11 +111,8 @@ func makeAppcast(archivesSourceDir: URL, cacheDirectory cacheDir: URL, keys: Pri do { // Decide the most appropriate delta version let deltaVersion: SUBinaryDeltaMajorVersion - if SUBinaryDeltaMajorVersionDefault == .version2 { - // Remove this branch when we change the default delta version to .version3 - deltaVersion = .version2 - } else if let frameworkVersion = item.frameworkVersion { - switch comparator.compareVersion(frameworkVersion, toVersion: "2009") { + if let frameworkVersion = item.frameworkVersion { + switch comparator.compareVersion(frameworkVersion, toVersion: "2010") { case .orderedSame: fallthrough case .orderedDescending: