Add additional options to delta tools (#2052)

This commit is contained in:
Zorg authored and GitHub committed 2022-01-04 00:14:45 -08:00
1 parent 23fc577184
commit 71fc8d7b11
23 files changed
+537 -345

No files matched your search

+6 -1
View File
@@ -79,14 +79,19 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
unsigned char _afterTreeHash[CC_SHA1_DIGEST_LENGTH];
}
@synthesize compression = _compression;
@synthesize compressionLevel = _compressionLevel;
@synthesize majorVersion = _majorVersion;
@synthesize minorVersion = _minorVersion;
- (instancetype)initWithMajorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash
- (instancetype)initWithCompression:(SPUDeltaCompressionMode)compression compressionLevel:(uint8_t)compressionLevel majorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash
{
self = [super init];
if (self != nil)
{
_compression = compression;
_compressionLevel = compressionLevel;
_majorVersion = majorVersion;
_minorVersion = minorVersion;
+4 -16
View File
@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import "SPUDeltaCompressionMode.h"
NS_ASSUME_NONNULL_BEGIN
@@ -22,26 +23,13 @@ typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
SPUDeltaItemCommandClone = (1u << 4),
};
// Compression mode to use during patch creation
typedef NS_ENUM(uint8_t, SPUDeltaCompressionMode) {
SPUDeltaCompressionModeNone = 0,
SPUDeltaCompressionModeBzip2,
SPUDeltaCompressionModeLZMA,
SPUDeltaCompressionModeLZFSE,
SPUDeltaCompressionModeLZ4,
SPUDeltaCompressionModeZLIB
};
// For Swift access
extern SPUDeltaCompressionMode SPUDeltaCompressionModeDefault;
#define DEFAULT_BZIP2_COMPRESSION_LEVEL 9
// Represents header for our archive
@interface SPUDeltaArchiveHeader : NSObject
- (instancetype)initWithMajorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash;
- (instancetype)initWithCompression:(SPUDeltaCompressionMode)compression compressionLevel:(uint8_t)compressionLevel majorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash;
@property (nonatomic, readonly) SPUDeltaCompressionMode compression;
@property (nonatomic, readonly) uint8_t compressionLevel;
@property (nonatomic, readonly) uint16_t majorVersion;
@property (nonatomic, readonly) uint16_t minorVersion;
@property (nonatomic, readonly) unsigned char *beforeTreeHash;
+22
View File
@@ -0,0 +1,22 @@
//
// SPUDeltaCompressionMode.h
// Sparkle
//
// Created by Mayur Pawashe on 1/3/22.
// Copyright © 2022 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
// Compression mode to use during patch creation
typedef NS_ENUM(uint8_t, SPUDeltaCompressionMode) {
SPUDeltaCompressionModeNone = 0,
SPUDeltaCompressionModeBzip2,
SPUDeltaCompressionModeLZMA,
SPUDeltaCompressionModeLZFSE,
SPUDeltaCompressionModeLZ4,
SPUDeltaCompressionModeZLIB
};
// For Swift access
extern SPUDeltaCompressionMode SPUDeltaCompressionModeDefault;
+2 -1
View File
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "SPUDeltaArchiveProtocol.h"
#import "SPUDeltaCompressionMode.h"
NS_ASSUME_NONNULL_BEGIN
@@ -66,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface SPUSparkleDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel;
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
@end
+44 -8
View File
@@ -35,7 +35,6 @@
@property (nonatomic) void *compressionBuffer;
@property (nonatomic) NSMutableArray<SPUDeltaArchiveItem *> *writableItems;
@property (nonatomic) int32_t writableCompressionLevel;
@end
@@ -52,7 +51,6 @@
@synthesize compression = _compression;
@synthesize writeMode = _writeMode;
@synthesize writableItems = _writableItems;
@synthesize writableCompressionLevel = _writableCompressionLevel;
@synthesize error = _error;
@synthesize partialChunkBuffer = _partialChunkBuffer;
@synthesize compressionBuffer = _compressionBuffer;
@@ -62,14 +60,12 @@
return YES;
}
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile
{
self = [super init];
if (self != nil) {
_patchFile = [patchFile copy];
_writableItems = [NSMutableArray array];
_compression = (compression == SPUDeltaCompressionModeDefault) ? SPUDeltaCompressionModeLZMA : compression;
_writableCompressionLevel = compressionLevel;
_writeMode = YES;
}
return self;
@@ -271,6 +267,12 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
self.compression = compression;
uint8_t compressionLevel = 0;
if (fread(&compressionLevel, sizeof(compressionLevel), 1, file) < 1) {
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read compression level value from patch file: %@", patchFile] }];
return nil;
}
switch (compression) {
case SPUDeltaCompressionModeNone:
break;
@@ -336,7 +338,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
return nil;
}
return [[SPUDeltaArchiveHeader alloc] initWithMajorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeTreeHash afterTreeHash:afterTreeHash];
return [[SPUDeltaArchiveHeader alloc] initWithCompression:compression compressionLevel:compressionLevel majorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeTreeHash afterTreeHash:afterTreeHash];
}
- (NSArray<NSString *> *)_readRelativeFilePaths
@@ -712,19 +714,53 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
return;
}
SPUDeltaCompressionMode compression = self.compression;
SPUDeltaCompressionMode compression = (header.compression == SPUDeltaCompressionModeDefault) ? SPUDeltaCompressionModeLZMA : header.compression;
self.compression = compression;
if (fwrite(&compression, sizeof(compression), 1, file) < 1) {
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write compression value due to io error" }];
return;
}
// We only support configuring compression level for bzip2
uint8_t compressionLevel = 0;
switch (compression) {
case SPUDeltaCompressionModeBzip2:
// Only 1 - 9 are valid, 0 is a special case for using default 9
if (header.compressionLevel <= 0 || header.compressionLevel > 9) {
compressionLevel = 9;
} else {
compressionLevel = header.compressionLevel;
}
break;
// Some supported formats below have a documented level even though it's not customizable
// Let's record them in the archive
case SPUDeltaCompressionModeLZMA:
compressionLevel = 6;
break;
case SPUDeltaCompressionModeZLIB:
compressionLevel = 5;
break;
// These formats don't have any documented level or aren't applicable
case SPUDeltaCompressionModeLZ4:
case SPUDeltaCompressionModeLZFSE:
case SPUDeltaCompressionModeNone:
compressionLevel = 0;
}
if (fwrite(&compressionLevel, sizeof(compressionLevel), 1, file) < 1) {
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write compression level value due to io error" }];
return;
}
switch (compression) {
case SPUDeltaCompressionModeNone:
break;
case SPUDeltaCompressionModeBzip2: {
int bzerror = 0;
// Compression level can be 1 - 9
int blockSize100k = self.writableCompressionLevel;
int blockSize100k = (int)compressionLevel;
BZFILE *bzipFile = BZ2_bzWriteOpen(&bzerror, file, blockSize100k, 0, 0);
if (bzipFile == NULL) {
+2 -1
View File
@@ -9,13 +9,14 @@
#import <Foundation/Foundation.h>
#import "SPUDeltaArchiveProtocol.h"
#import "SPUDeltaCompressionMode.h"
NS_ASSUME_NONNULL_BEGIN
// Legacy container format for binary delta archives
@interface SPUXarDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel;
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
@end
+15 -12
View File
@@ -53,9 +53,6 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
@property (nonatomic, readonly) NSString *patchFile;
@property (nonatomic) NSError *error;
@property (nonatomic, readonly) SPUDeltaCompressionMode writableCompression;
@property (nonatomic, readonly) int32_t writableCompressionLevel;
@end
@implementation SPUXarDeltaArchive
@@ -64,18 +61,14 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
@synthesize xarMode = _xarMode;
@synthesize patchFile = _patchFile;
@synthesize fileTable = _fileTable;
@synthesize writableCompression = _writableCompression;
@synthesize writableCompressionLevel = _writableCompressionLevel;
@synthesize error = _error;
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile
{
self = [super init];
if (self != nil) {
_patchFile = [patchFile copy];
_xarMode = WRITE;
_writableCompression = (compression == SPUDeltaCompressionModeDefault ? SPUDeltaCompressionModeBzip2 : compression);
_writableCompressionLevel = compressionLevel;
_fileTable = [NSMutableDictionary dictionary];
}
return self;
@@ -121,7 +114,7 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
self.x = x;
uint16_t majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
uint16_t majorDiffVersion = SUBinaryDeltaMajorVersionFirst;
uint16_t minorDiffVersion = 0;
NSString *expectedBeforeHash = nil;
NSString *expectedAfterHash = nil;
@@ -173,7 +166,9 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
unsigned char rawExpectedAfterHash[CC_SHA1_DIGEST_LENGTH] = {0};
getRawHashFromDisplayHash(rawExpectedAfterHash, expectedAfterHash);
return [[SPUDeltaArchiveHeader alloc] initWithMajorVersion:majorDiffVersion minorVersion:minorDiffVersion beforeTreeHash:rawExpectedBeforeHash afterTreeHash:rawExpectedAfterHash];
// I wasn't able to figure out how to retrieve the compression options from xar,
// so we will use default flags to indicate the info isn't available
return [[SPUDeltaArchiveHeader alloc] initWithCompression:SPUDeltaCompressionModeDefault compressionLevel:0 majorVersion:majorDiffVersion minorVersion:minorDiffVersion beforeTreeHash:rawExpectedBeforeHash afterTreeHash:rawExpectedAfterHash];
}
- (void)writeHeader:(SPUDeltaArchiveHeader *)header
@@ -188,11 +183,19 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
self.x = x;
SPUDeltaCompressionMode compression = self.writableCompression;
int32_t compressionLevel = self.writableCompressionLevel;
SPUDeltaCompressionMode compression = (header.compression == SPUDeltaCompressionModeDefault ? SPUDeltaCompressionModeBzip2 : header.compression);
uint8_t compressionLevel;
// Only 1 - 9 are valid, 0 is special case to use default level 9
if (header.compressionLevel <= 0 || header.compressionLevel > 9) {
compressionLevel = 9;
} else {
compressionLevel = header.compressionLevel;
}
switch (compression) {
case SPUDeltaCompressionModeNone:
xar_opt_set(x, XAR_OPT_COMPRESSION, XAR_OPT_VAL_NONE);
break;
case SPUDeltaCompressionModeBzip2: {
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
+4 -4
View File
@@ -46,23 +46,23 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
unsigned char *expectedBeforeHash = header.beforeTreeHash;
unsigned char *expectedAfterHash = header.afterTreeHash;
if (majorDiffVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
if (majorDiffVersion < SUBinaryDeltaMajorVersionFirst) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to identify diff-version %u in delta. Giving up.", majorDiffVersion] }];
}
return NO;
}
if (majorDiffVersion < FIRST_SUPPORTED_DELTA_MAJOR_VERSION) {
if (majorDiffVersion < SUBinaryDeltaMajorVersionFirstSupported) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Applying version %u patches is no longer supported.", majorDiffVersion] }];
}
return NO;
}
if (majorDiffVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
if (majorDiffVersion > SUBinaryDeltaMajorVersionLatest) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A later version is needed to apply this patch (on major version %u, but patch requests version %u).", LATEST_DELTA_DIFF_MAJOR_VERSION, majorDiffVersion] }];
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A later version is needed to apply this patch (on major version %u, but patch requests version %u).", SUBinaryDeltaMajorVersionLatest, majorDiffVersion] }];
}
return NO;
}
+10 -5
View File
@@ -10,7 +10,7 @@
#define SUBINARYDELTACOMMON_H
#import <Foundation/Foundation.h>
#import "SPUDeltaCompressionMode.h"
#include <fts.h>
#define PERMISSION_FLAGS (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)
@@ -40,12 +40,17 @@ typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
SUBinaryDeltaMajorVersion3 = 3
};
// For Swift access
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault;
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionLatest;
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst;
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported;
#define FIRST_DELTA_DIFF_MAJOR_VERSION SUBinaryDeltaMajorVersion1
#define FIRST_SUPPORTED_DELTA_MAJOR_VERSION SUBinaryDeltaMajorVersion2
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBinaryDeltaMajorVersion3
#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_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."
SPUDeltaCompressionMode deltaCompressionModeFromDescription(NSString *description, BOOL *requestValid);
NSString *deltaCompressionStringFromMode(SPUDeltaCompressionMode mode);
extern int compareFiles(const FTSENT **a, const FTSENT **b);
BOOL getRawHashOfTreeWithVersion(unsigned char *hashBuffer, NSString *path, uint16_t majorVersion);
+67 -1
View File
@@ -19,7 +19,73 @@
#include "AppKitPrevention.h"
// 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 SUBinaryDeltaMajorVersionLatest = SUBinaryDeltaMajorVersion3;
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst = SUBinaryDeltaMajorVersion1;
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported = SUBinaryDeltaMajorVersion2;
SPUDeltaCompressionMode deltaCompressionModeFromDescription(NSString *requestedDescription, BOOL *requestValid)
{
// Set to NO later if request was not valid
if (requestValid != NULL) {
*requestValid = YES;
}
SPUDeltaCompressionMode compression;
NSString *description = requestedDescription.lowercaseString;
if ([description isEqualToString:@"default"]) {
compression = SPUDeltaCompressionModeDefault;
} else if ([description isEqualToString:@"none"]) {
compression = SPUDeltaCompressionModeNone;
} else if ([description isEqualToString:@"bzip2"]) {
compression = SPUDeltaCompressionModeBzip2;
} else if ([description isEqualToString:@"lzma"]) {
compression = SPUDeltaCompressionModeLZMA;
} else if ([description isEqualToString:@"lzfse"]) {
compression = SPUDeltaCompressionModeLZFSE;
} else if ([description isEqualToString:@"lz4"]) {
compression = SPUDeltaCompressionModeLZ4;
} else if ([description isEqualToString:@"zlib"]) {
compression = SPUDeltaCompressionModeZLIB;
} else {
compression = SPUDeltaCompressionModeDefault;
if (requestValid != NULL) {
*requestValid = NO;
}
}
return compression;
}
NSString *deltaCompressionStringFromMode(SPUDeltaCompressionMode mode)
{
switch (mode) {
case SPUDeltaCompressionModeBzip2:
return @"bzip2";
case SPUDeltaCompressionModeLZMA:
return @"LZMA";
case SPUDeltaCompressionModeNone:
return @"no";
case SPUDeltaCompressionModeLZ4:
return @"LZ4";
case SPUDeltaCompressionModeLZFSE:
return @"LZFSE";
case SPUDeltaCompressionModeZLIB:
return @"ZLIB";
default:
break;
}
if (mode == SPUDeltaCompressionModeDefault) {
return @"default";
}
return @"unknown";
}
int compareFiles(const FTSENT **a, const FTSENT **b)
{
@@ -252,7 +318,7 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
extern NSString *hashOfTree(NSString *path)
{
return hashOfTreeWithVersion(path, LATEST_DELTA_DIFF_MAJOR_VERSION);
return hashOfTreeWithVersion(path, SUBinaryDeltaMajorVersionLatest);
}
BOOL removeTree(NSString *path)
+1 -1
View File
@@ -13,6 +13,6 @@
#import "SPUDeltaArchiveProtocol.h"
@class NSString;
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, int32_t compressionLevel, BOOL verbose, NSError * __autoreleasing *error);
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, uint8_t compressionLevel, BOOL verbose, NSError * __autoreleasing *error);
#endif
+6 -6
View File
@@ -297,12 +297,12 @@ static NSString *cloneableRelativePath(NSDictionary<NSString *, NSData *> *after
return nil;
}
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, int32_t compressionLevel, BOOL verbose, NSError *__autoreleasing *error)
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, uint8_t compressionLevel, BOOL verbose, NSError *__autoreleasing *error)
{
assert(source);
assert(destination);
assert(patchFile);
assert(majorVersion >= FIRST_DELTA_DIFF_MAJOR_VERSION && majorVersion <= LATEST_DELTA_DIFF_MAJOR_VERSION);
assert(majorVersion >= SUBinaryDeltaMajorVersionFirst && majorVersion <= SUBinaryDeltaMajorVersionLatest);
uint16_t minorVersion = latestMinorVersionForMajorVersion(majorVersion);
@@ -326,7 +326,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
}
if (verbose) {
fprintf(stderr, "Creating version %u.%u patch...\n", majorVersion, minorVersion);
fprintf(stderr, "Creating version %u.%u patch using %s compression...\n", majorVersion, minorVersion, deltaCompressionStringFromMode(compression).UTF8String);
fprintf(stderr, "Processing source, %s...", [source fileSystemRepresentation]);
}
@@ -508,12 +508,12 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
id<SPUDeltaArchiveProtocol> archive;
if (majorVersion >= SUBinaryDeltaMajorVersion3) {
archive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile compression:compression compressionLevel:compressionLevel];
archive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile];
} else {
archive = [[SPUXarDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile compression:compression compressionLevel:compressionLevel];
archive = [[SPUXarDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile];
}
SPUDeltaArchiveHeader *header = [[SPUDeltaArchiveHeader alloc] initWithMajorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeHash afterTreeHash:afterHash];
SPUDeltaArchiveHeader *header = [[SPUDeltaArchiveHeader alloc] initWithCompression:compression compressionLevel:compressionLevel majorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeHash afterTreeHash:afterHash];
[archive writeHeader:header];
if (archive.error != nil) {
-270
View File
@@ -1,270 +0,0 @@
//
// SUBinaryDeltaTool.m
// Sparkle
//
// Created by Mark Rowe on 2009-06-01.
// Copyright 2009 Mark Rowe. All rights reserved.
//
#import "SUBinaryDeltaApply.h"
#import "SUBinaryDeltaCreate.h"
#import "SPUDeltaArchive.h"
#import "SPUDeltaArchiveProtocol.h"
#import <Foundation/Foundation.h>
#define VERBOSE_FLAG @"--verbose"
#define VERSION_FLAG @"--version"
#define CREATE_COMMAND @"create"
#define APPLY_COMMAND @"apply"
#define VERSION_COMMAND @"version"
#define VERSION_ALTERNATE_COMMAND @"--version"
#include "AppKitPrevention.h"
static void printUsage(NSString *programName)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "%s create [--verbose] [--version=<version>] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
fprintf(stderr, "%s apply [--verbose] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
fprintf(stderr, "%s version [<patch-file>]\n", [programName UTF8String]);
}
static BOOL runCreateCommand(NSString *programName, NSArray<NSString *> *args)
{
if (args.count < 3 || args.count > 5) {
printUsage(programName);
return NO;
}
NSUInteger numberOflagsFound = 0;
NSUInteger verboseIndex = [args indexOfObject:VERBOSE_FLAG];
NSUInteger versionIndex = NSNotFound;
for (NSUInteger argumentIndex = 0; argumentIndex < args.count; ++argumentIndex) {
if ([args[argumentIndex] hasPrefix:VERSION_FLAG]) {
versionIndex = argumentIndex;
break;
}
}
if (verboseIndex != NSNotFound) {
++numberOflagsFound;
}
if (versionIndex != NSNotFound) {
++numberOflagsFound;
}
if (args.count - numberOflagsFound < 3) {
printUsage(programName);
return NO;
}
BOOL verbose = (verboseIndex != NSNotFound);
NSString *versionField = (versionIndex != NSNotFound) ? args[versionIndex] : nil;
NSArray<NSString *> *versionComponents = nil;
if (versionField) {
versionComponents = [versionField componentsSeparatedByString:@"="];
if (versionComponents.count != 2) {
printUsage(programName);
return NO;
}
}
SUBinaryDeltaMajorVersion patchVersion =
!versionComponents ?
SUBinaryDeltaMajorVersionDefault :
(SUBinaryDeltaMajorVersion)[[versionComponents[1] componentsSeparatedByString:@"."][0] intValue]; // ignore minor version if provided
if (patchVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
fprintf(stderr, "Version provided (%u) is not valid\n", patchVersion);
return NO;
}
if (patchVersion < FIRST_SUPPORTED_DELTA_MAJOR_VERSION) {
fprintf(stderr, "Creating version %u patches is no longer supported.\n", patchVersion);
return NO;
}
if (patchVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
fprintf(stderr, "This program is too old to create a version %u patch, or the version number provided is invalid\n", patchVersion);
return NO;
}
NSMutableArray *fileArgs = [NSMutableArray array];
for (NSString *argument in args) {
if (![argument hasPrefix:VERSION_FLAG] && ![argument isEqualToString:VERBOSE_FLAG]) {
[fileArgs addObject:argument];
}
}
if (fileArgs.count != 3) {
printUsage(programName);
return NO;
}
NSString *sourcePath = fileArgs[0];
NSString *destPath = fileArgs[1];
NSString *patchPath = fileArgs[2];
BOOL isDirectory;
if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath isDirectory:&isDirectory] || !isDirectory) {
printUsage(programName);
fprintf(stderr, "Error: before-tree must be a directory\n");
return NO;
}
if (![[NSFileManager defaultManager] fileExistsAtPath:destPath isDirectory:&isDirectory] || !isDirectory) {
printUsage(programName);
fprintf(stderr, "Error: after-tree must be a directory\n");
return NO;
}
// Until we have a better way of passing/parsing command line options we'll use environment variables
SPUDeltaCompressionMode compression;
const char *compressionEnv = getenv("SPARKLE_DELTA_COMPRESSION");
if (compressionEnv == NULL) {
compression = SPUDeltaCompressionModeDefault;
} else if (strcmp(compressionEnv, "bzip2") == 0) {
compression = SPUDeltaCompressionModeBzip2;
} else if (strcmp(compressionEnv, "lzma") == 0) {
compression = SPUDeltaCompressionModeLZMA;
} else if (strcmp(compressionEnv, "lzfse") == 0) {
compression = SPUDeltaCompressionModeLZFSE;
} else if (strcmp(compressionEnv, "lz4") == 0) {
compression = SPUDeltaCompressionModeLZ4;
} else if (strcmp(compressionEnv, "zlib") == 0) {
compression = SPUDeltaCompressionModeZLIB;
} else {
compression = SPUDeltaCompressionModeNone;
}
int32_t compressionLevel;
const char *compressionLevelEnv = getenv("SPARKLE_DELTA_COMPRESSION_LEVEL");
if (compressionLevelEnv == NULL) {
compressionLevel = DEFAULT_BZIP2_COMPRESSION_LEVEL;
} else {
compressionLevel = atoi(compressionLevelEnv);
}
NSError *createDiffError = nil;
if (!createBinaryDelta(sourcePath, destPath, patchPath, patchVersion, compression, compressionLevel, verbose, &createDiffError)) {
fprintf(stderr, "%s\n", [createDiffError.localizedDescription UTF8String]);
return NO;
}
return YES;
}
static BOOL runApplyCommand(NSString *programName, NSArray *args)
{
if (args.count < 3 || args.count > 4) {
printUsage(programName);
return NO;
}
BOOL verbose = [args containsObject:VERBOSE_FLAG];
if (args.count == 4 && !verbose) {
printUsage(programName);
return NO;
}
NSMutableArray *fileArgs = [NSMutableArray array];
for (NSString *argument in args) {
if (![argument isEqualToString:VERBOSE_FLAG]) {
[fileArgs addObject:argument];
}
}
if (fileArgs.count != 3) {
printUsage(programName);
return NO;
}
BOOL isDirectory;
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) {
printUsage(programName);
fprintf(stderr, "Error: before-tree must be a directory\n");
return NO;
}
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[2] isDirectory:&isDirectory] || isDirectory) {
printUsage(programName);
fprintf(stderr, "Error: patch-file must be a file %d\n", isDirectory);
return NO;
}
NSError *applyDiffError = nil;
if (!applyBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], verbose, ^(__unused double x){}, &applyDiffError)) {
fprintf(stderr, "%s\n", [applyDiffError.localizedDescription UTF8String]);
return NO;
}
return YES;
}
static BOOL runVersionCommand(NSString *programName, NSArray *args)
{
if (args.count > 1) {
printUsage(programName);
return NO;
}
if (args.count == 0) {
fprintf(stdout, "%u.%u\n", LATEST_DELTA_DIFF_MAJOR_VERSION, latestMinorVersionForMajorVersion(LATEST_DELTA_DIFF_MAJOR_VERSION));
} else {
NSString *patchFile = args[0];
uint16_t majorDiffVersion = 0;
uint16_t minorDiffVersion = 0;
SPUDeltaArchiveHeader *header = nil;
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveReadPatchAndHeader(patchFile, &header);
if (archive.error != nil) {
fprintf(stderr, "Unable to open patch %s\n", [patchFile fileSystemRepresentation]);
fprintf(stderr, "%s\n", archive.error.localizedDescription.UTF8String);
return NO;
}
if (header.majorVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
fprintf(stderr, "Unable to retrieve version information from patch %s\n", [patchFile fileSystemRepresentation]);
return NO;
}
fprintf(stdout, "%u.%u\n", majorDiffVersion, minorDiffVersion);
}
return YES;
}
int main(int __unused argc, char __unused *argv[])
{
@autoreleasepool {
NSArray<NSString *> *args = [[NSProcessInfo processInfo] arguments];
NSString *programName = [args[0] lastPathComponent];
if (args.count < 2) {
printUsage(programName);
return 1;
}
NSString *command = args[1];
NSArray *commandArguments = [args subarrayWithRange:NSMakeRange(2, args.count - 2)];
BOOL result;
if ([command isEqualToString:CREATE_COMMAND]) {
result = runCreateCommand(programName, commandArguments);
} else if ([command isEqualToString:APPLY_COMMAND]) {
result = runApplyCommand(programName, commandArguments);
} else if ([command isEqualToString:VERSION_COMMAND] || [command isEqualToString:VERSION_ALTERNATE_COMMAND]) {
result = runVersionCommand(programName, commandArguments);
} else {
result = NO;
printUsage(programName);
}
return result ? 0 : 1;
}
}
+8
View File
@@ -0,0 +1,8 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "SUBinaryDeltaApply.h"
#import "SUBinaryDeltaCreate.h"
#import "SPUDeltaArchive.h"
#import "SPUDeltaArchiveProtocol.h"
+228
View File
@@ -0,0 +1,228 @@
//
// main.swift
// BinaryDelta
//
// Created by Mayur Pawashe on 1/3/22.
// Copyright © 2022 Sparkle Project. All rights reserved.
//
import Foundation
import ArgumentParser
// Create a patch from an old and new bundle
struct Create: ParsableCommand {
@Option(name: .long, help: ArgumentHelp("The major version of the patch to generate. Defaults to the latest stable version. Older versions will need to be specified for updating from applications using older versions of Sparkle.", valueName: "version"))
var version: Int = Int(SUBinaryDeltaMajorVersionDefault.rawValue)
@Flag(name: .customLong("verbose"), help: ArgumentHelp("Enable logging of the changes being archived into the generated patch."))
var verbose: Bool = false
@Option(name: .long, help: ArgumentHelp(COMPRESSION_METHOD_ARGUMENT_DESCRIPTION, valueName: "compression"))
var compression: String = "default"
@Option(name: .long, help: ArgumentHelp(COMPRESSION_LEVEL_ARGUMENT_DESCRIPTION, valueName: "compression-level"))
var compressionLevel: UInt8 = 0
@Argument(help: ArgumentHelp("Path to original bundle to create a patch from."))
var beforeTree: String
@Argument(help: ArgumentHelp("Path to new bundle to create a patch from."))
var afterTree: String
@Argument(help: ArgumentHelp("Path to new patch file to create."))
var patchFile: String
func validate() throws {
var validCompression: ObjCBool = false
let compressionMode = deltaCompressionModeFromDescription(compression, &validCompression)
guard validCompression.boolValue else {
fputs("Error: unrecognized compression \(compression)\n", stderr)
throw ExitCode(1)
}
switch compressionMode {
case SPUDeltaCompressionModeDefault:
fallthrough
case .none:
guard compressionLevel == 0 else {
fputs("Error: compression level must be 0 for compression \(compression)\n", stderr)
throw ExitCode(1)
}
break
case .bzip2:
guard compressionLevel >= 0 && compressionLevel <= 9 else {
fputs("Error: compression level \(compressionLevel) is not valid.\n", stderr)
throw ExitCode(1)
}
break
case .LZMA:
fallthrough
case .LZFSE:
fallthrough
case .LZ4:
fallthrough
case .ZLIB:
guard version >= 3 else {
fputs("Error: version \(version) patch files do not support compression \(compression)\n", stderr)
throw ExitCode(1)
}
guard compressionLevel == 0 else {
fputs("Error: compression level provided must be 0 for compression \(compression)\n", stderr)
throw ExitCode(1)
}
break
@unknown default:
fputs("Error: unrecognized compression \(compression)\n", stderr)
throw ExitCode(1)
}
guard version >= SUBinaryDeltaMajorVersionFirst.rawValue else {
fputs("Error: version provided \(version) is not valid.\n", stderr)
throw ExitCode(1)
}
guard version >= SUBinaryDeltaMajorVersionFirstSupported.rawValue else {
fputs("Error: creating version \(version) patches is no longer supported.\n", stderr)
throw ExitCode(1)
}
guard version <= SUBinaryDeltaMajorVersionLatest.rawValue else {
fputs("Error: this program is too old to create a version \(version) patch, or the version number provided is invalid.\n", stderr)
throw ExitCode(1)
}
let fileManager = FileManager.default
var isDirectory: ObjCBool = false
if !fileManager.fileExists(atPath: beforeTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
fputs("Error: before-tree must be a directory\n", stderr)
throw ExitCode(1)
}
if !fileManager.fileExists(atPath: afterTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
fputs("Error: after-tree must be a directory\n", stderr)
throw ExitCode(1)
}
}
func run() throws {
let compressionMode = deltaCompressionModeFromDescription(compression, nil)
guard let majorDeltaVersion = SUBinaryDeltaMajorVersion(rawValue: UInt16(version)) else {
// We shouldn't reach here
fputs("Error: failed to retrieve major version from provided version: \(version)\n", stderr)
throw ExitCode(1)
}
var createDiffError: NSError? = nil
if !createBinaryDelta(beforeTree, afterTree, patchFile, majorDeltaVersion, compressionMode, compressionLevel, verbose, &createDiffError) {
if let error = createDiffError {
fputs("\(error.localizedDescription)\n", stderr)
} else {
fputs("Error: Failed to create patch due to unknown reason.\n", stderr)
}
throw ExitCode(1)
}
}
}
// Apply a patch from an old bundle to generate a new bundle
struct Apply: ParsableCommand {
static let configuration = CommandConfiguration(abstract: "Apply a patch against an original bundle to generate a new bundle.")
@Flag(name: .customLong("verbose"), help: ArgumentHelp("Enable logging of changes being applied from the patch."))
var verbose: Bool = false
@Argument(help: ArgumentHelp("Path to original bundle to patch."))
var beforeTree: String
@Argument(help: ArgumentHelp("Path to new bundle to create."))
var afterTree: String
@Argument(help: ArgumentHelp("Path to patch file to apply."))
var patchFile: String
func validate() throws {
let fileManager = FileManager.default
var isDirectory: ObjCBool = false
if !fileManager.fileExists(atPath: beforeTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
fputs("Error: before-tree must be a directory\n", stderr)
throw ExitCode(1)
}
if !fileManager.fileExists(atPath: patchFile, isDirectory: &isDirectory) || isDirectory.boolValue {
fputs("Error: patch-file must be a file\n", stderr)
throw ExitCode(1)
}
}
func run() throws {
var applyDiffError: NSError?
if (!applyBinaryDelta(beforeTree, afterTree, patchFile, verbose, { _ in }, &applyDiffError)) {
if let error = applyDiffError {
fputs("\(error.localizedDescription)\n", stderr)
} else {
fputs("Error: patch failed to apply for unknown reason\n", stderr)
}
throw ExitCode(1)
}
}
}
// Output information for BinaryDelta or from a patch file
struct Info: ParsableCommand {
@Argument(help: ArgumentHelp("Path to patch file to extract information from."))
var patchFile : String?
func run() throws {
if let patchFile = patchFile {
// Print version of patch file
var header: SPUDeltaArchiveHeader? = nil
let archive = SPUDeltaArchiveReadPatchAndHeader(patchFile, &header)
if let error = archive.error {
fputs("Error: Unable to open patch \(patchFile): \(error.localizedDescription)\n", stderr)
throw ExitCode(1)
}
if let header = header {
if header.majorVersion < SUBinaryDeltaMajorVersionFirst.rawValue {
fputs("Error: major version \(header.majorVersion) is invalid.\n", stderr)
throw ExitCode(1)
}
fputs("Patch version \(header.majorVersion).\(header.minorVersion)", stdout)
// Print out compression info only if it's available
// We can't get compression info from version 2 files
if header.compression != SPUDeltaCompressionModeDefault, let compressionDescription = deltaCompressionStringFromMode(header.compression) {
fputs(" using \(compressionDescription) compression", stdout)
// Compression level isn't available or applicable for all formats
if header.compressionLevel != 0 {
fputs(" with level \(header.compressionLevel)", stdout)
}
}
fputs("\n", stdout)
} else {
fputs("Error: Failed to retrieve header due to unknown reason.\n", stderr)
throw ExitCode(1)
}
} else {
// Print version of program
fputs("BinaryDelta version \(SUBinaryDeltaMajorVersionLatest.rawValue).\(latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersionLatest))\n", stdout)
}
}
}
struct BinaryDelta: ParsableCommand {
static let configuration = CommandConfiguration(commandName: "BinaryDelta", abstract: "Create and apply small and efficient delta patches between an old and new version of a bundle.", subcommands: [Create.self, Apply.self, Info.self])
}
DispatchQueue.global().async(execute: {
BinaryDelta.main()
CFRunLoopStop(CFRunLoopGetMain())
})
CFRunLoopRun()
@@ -1 +0,0 @@
// BinaryDelta tool only
+1 -1
View File
@@ -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 = 2008
CURRENT_PROJECT_VERSION = 2009
MARKETING_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)$(SPARKLE_VERSION_SUFFIX)
ALWAYS_SEARCH_USER_PATHS = NO
+24 -9
View File
@@ -218,6 +218,8 @@
725B81FA2781AEAF0041746F /* libcompression.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 725B81F92781AEA40041746F /* libcompression.tbd */; };
725B81FB2781CD930041746F /* libcompression.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 725B81F92781AEA40041746F /* libcompression.tbd */; };
725B81FC2781CDC20041746F /* libcompression.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 725B81F92781AEA40041746F /* libcompression.tbd */; };
725C2EAA2782EC61007CB7B5 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 725C2EA92782EC61007CB7B5 /* main.swift */; };
725C2EAC2782EF3C007CB7B5 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 725C2EAB2782EF3C007CB7B5 /* ArgumentParser */; };
725CB9571C7120410064365A /* SPUUserDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 725CB9561C7120410064365A /* SPUUserDriver.h */; settings = {ATTRIBUTES = (Public, ); }; };
725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 725CB9581C7121830064365A /* SPUStandardUserDriver.h */; settings = {ATTRIBUTES = (Public, ); }; };
725CB95B1C7121830064365A /* SPUStandardUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 725CB9591C7121830064365A /* SPUStandardUserDriver.m */; };
@@ -240,7 +242,6 @@
7267E5781D3D895B00D1BF90 /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5711D3D895B00D1BF90 /* SUBinaryDeltaCommon.m */; };
7267E5791D3D895B00D1BF90 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5731D3D895B00D1BF90 /* SUBinaryDeltaCreate.m */; };
7267E57A1D3D895B00D1BF90 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5731D3D895B00D1BF90 /* SUBinaryDeltaCreate.m */; };
7267E57C1D3D895B00D1BF90 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5741D3D895B00D1BF90 /* SUBinaryDeltaTool.m */; };
7267E57F1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E57E1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.m */; };
7267E5861D3D89B300D1BF90 /* SUDiskImageUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5811D3D89B300D1BF90 /* SUDiskImageUnarchiver.m */; };
7267E5871D3D89B300D1BF90 /* SUPipedUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5831D3D89B300D1BF90 /* SUPipedUnarchiver.m */; };
@@ -882,7 +883,6 @@
5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BinaryDelta; sourceTree = BUILT_PRODUCTS_DIR; };
5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */ = {isa = PBXFileReference; comments = "-Wno-shorten-64-to-32"; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bsdiff.c; sourceTree = "<group>"; };
5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bspatch.c; sourceTree = "<group>"; };
5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigBinaryDelta.xcconfig; sourceTree = "<group>"; };
5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbz2.dylib; path = usr/lib/libbz2.dylib; sourceTree = SDKROOT; };
5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxar.1.dylib; path = usr/lib/libxar.1.dylib; sourceTree = SDKROOT; };
5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
@@ -1144,6 +1144,9 @@
72563CA9272E1C5400AF39F0 /* .github */ = {isa = PBXFileReference; lastKnownFileType = folder; path = .github; sourceTree = "<group>"; };
725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_minimumAutoupdateVersion.xml; sourceTree = "<group>"; };
725B81F92781AEA40041746F /* libcompression.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcompression.tbd; path = usr/lib/libcompression.tbd; sourceTree = SDKROOT; };
725C2EA82782EC44007CB7B5 /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Bridging-Header.h"; path = "BinaryDelta/Bridging-Header.h"; sourceTree = SOURCE_ROOT; };
725C2EA92782EC61007CB7B5 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = BinaryDelta/main.swift; sourceTree = SOURCE_ROOT; };
725C2EAD278386A8007CB7B5 /* SPUDeltaCompressionMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SPUDeltaCompressionMode.h; path = Autoupdate/SPUDeltaCompressionMode.h; sourceTree = SOURCE_ROOT; };
725CB9561C7120410064365A /* SPUUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUserDriver.h; sourceTree = "<group>"; };
725CB9581C7121830064365A /* SPUStandardUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStandardUserDriver.h; sourceTree = "<group>"; };
725CB9591C7121830064365A /* SPUStandardUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUStandardUserDriver.m; sourceTree = "<group>"; };
@@ -1166,7 +1169,6 @@
7267E5711D3D895B00D1BF90 /* SUBinaryDeltaCommon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUBinaryDeltaCommon.m; path = Autoupdate/SUBinaryDeltaCommon.m; sourceTree = SOURCE_ROOT; };
7267E5721D3D895B00D1BF90 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUBinaryDeltaCreate.h; path = Autoupdate/SUBinaryDeltaCreate.h; sourceTree = SOURCE_ROOT; };
7267E5731D3D895B00D1BF90 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUBinaryDeltaCreate.m; path = Autoupdate/SUBinaryDeltaCreate.m; sourceTree = SOURCE_ROOT; };
7267E5741D3D895B00D1BF90 /* SUBinaryDeltaTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUBinaryDeltaTool.m; path = Autoupdate/SUBinaryDeltaTool.m; sourceTree = SOURCE_ROOT; };
7267E57D1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUBinaryDeltaUnarchiver.h; path = Autoupdate/SUBinaryDeltaUnarchiver.h; sourceTree = SOURCE_ROOT; };
7267E57E1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUBinaryDeltaUnarchiver.m; path = Autoupdate/SUBinaryDeltaUnarchiver.m; sourceTree = SOURCE_ROOT; };
7267E5801D3D89B300D1BF90 /* SUDiskImageUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUDiskImageUnarchiver.h; path = Autoupdate/SUDiskImageUnarchiver.h; sourceTree = SOURCE_ROOT; };
@@ -1406,6 +1408,7 @@
files = (
EA1E281922B645D9004AA304 /* libbsdiff.a in Frameworks */,
5D06E9050FD68D7D005AE3F6 /* Foundation.framework in Frameworks */,
725C2EAC2782EF3C007CB7B5 /* ArgumentParser in Frameworks */,
5D06E8FF0FD68D6D005AE3F6 /* libbz2.dylib in Frameworks */,
5D1AF58B0FD7678C0065DB48 /* libxar.1.dylib in Frameworks */,
5D1AF5900FD767AD0065DB48 /* libxml2.dylib in Frameworks */,
@@ -1788,15 +1791,17 @@
7267E5721D3D895B00D1BF90 /* SUBinaryDeltaCreate.h */,
7267E5731D3D895B00D1BF90 /* SUBinaryDeltaCreate.m */,
725EE481277BF17A00D820CE /* SPUDeltaArchiveProtocol.h */,
725C2EAD278386A8007CB7B5 /* SPUDeltaCompressionMode.h */,
725EE484277D375F00D820CE /* SPUDeltaArchive.h */,
725EE485277D375F00D820CE /* SPUDeltaArchive.m */,
728ED348277DA23400D9238F /* SPUSparkleDeltaArchive.h */,
728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */,
725EE47E277BF13A00D820CE /* SPUXarDeltaArchive.h */,
725EE47F277BF13B00D820CE /* SPUXarDeltaArchive.m */,
7267E5741D3D895B00D1BF90 /* SUBinaryDeltaTool.m */,
7267E57D1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.h */,
7267E57E1D3D896700D1BF90 /* SUBinaryDeltaUnarchiver.m */,
725C2EA92782EC61007CB7B5 /* main.swift */,
725C2EA82782EC44007CB7B5 /* Bridging-Header.h */,
);
name = "Binary Delta";
sourceTree = "<group>";
@@ -2335,7 +2340,6 @@
EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */,
EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */,
EA1E286922B664FD004AA304 /* CommandLineTool-Shared.xcconfig */,
5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */,
FA1941D00D94A70100DD942E /* ConfigCommon.xcconfig */,
149B78631B7D3A0C00D7D62C /* ConfigCommonCoverage.xcconfig */,
FA1941CF0D94A70100DD942E /* ConfigCommonDebug.xcconfig */,
@@ -2510,6 +2514,9 @@
376769AF23442F320077B8F7 /* PBXTargetDependency */,
);
name = BinaryDelta;
packageProductDependencies = (
725C2EAB2782EF3C007CB7B5 /* ArgumentParser */,
);
productName = BinaryDelta;
productReference = 5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */;
productType = "com.apple.product-type.tool";
@@ -2846,6 +2853,9 @@
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "Sparkle Project";
TargetAttributes = {
5D06E8CF0FD68C7C005AE3F6 = {
LastSwiftMigration = 1320;
};
612279D80DB5470200AB99EA = {
LastSwiftMigration = 0800;
TestTargetID = 8DC2EF4F0486A6940098B216;
@@ -3190,11 +3200,11 @@
files = (
725EE482277BF44A00D820CE /* SPUXarDeltaArchive.m in Sources */,
728ED34C277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */,
725C2EAA2782EC61007CB7B5 /* main.swift in Sources */,
7267E5761D3D895B00D1BF90 /* SUBinaryDeltaApply.m in Sources */,
725EE487277D376000D820CE /* SPUDeltaArchive.m in Sources */,
7267E5781D3D895B00D1BF90 /* SUBinaryDeltaCommon.m in Sources */,
7267E57A1D3D895B00D1BF90 /* SUBinaryDeltaCreate.m in Sources */,
7267E57C1D3D895B00D1BF90 /* SUBinaryDeltaTool.m in Sources */,
726F2CE81BC9C48F001971A4 /* SUConstants.m in Sources */,
7267E5EA1D3D90AA00D1BF90 /* SUFileManager.m in Sources */,
726F2CE91BC9C499001971A4 /* SUOperatingSystem.m in Sources */,
@@ -3948,7 +3958,7 @@
};
149B785E1B7D398100D7D62C /* Coverage */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */;
baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */;
buildSettings = {
};
name = Coverage;
@@ -3995,14 +4005,14 @@
};
5D06E8D20FD68C7D005AE3F6 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */;
baseConfigurationReference = EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */;
buildSettings = {
};
name = Debug;
};
5D06E8D30FD68C7D005AE3F6 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */;
baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */;
buildSettings = {
};
name = Release;
@@ -4590,6 +4600,11 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
725C2EAB2782EF3C007CB7B5 /* ArgumentParser */ = {
isa = XCSwiftPackageProductDependency;
package = 727DBAE326B5BBFD00111F0C /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
productName = ArgumentParser;
};
727DBAE426B5BBFD00111F0C /* ArgumentParser */ = {
isa = XCSwiftPackageProductDependency;
package = 727DBAE326B5BBFD00111F0C /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
+2 -2
View File
@@ -65,7 +65,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
}
NSError *createDiffError = nil;
BOOL createdDiff = createBinaryDelta(sourceDirectory, destinationDirectory, diffFile, majorVersion, compressionMode, DEFAULT_BZIP2_COMPRESSION_LEVEL, NO, &createDiffError);
BOOL createdDiff = createBinaryDelta(sourceDirectory, destinationDirectory, diffFile, majorVersion, compressionMode, 0, NO, &createDiffError);
if (!createdDiff) {
NSLog(@"Creating binary diff failed with error: %@", createDiffError);
} else if (afterDiffHandler != nil) {
@@ -92,7 +92,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
- (BOOL)createAndApplyPatchWithBeforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
{
XCTAssertEqual(SUBinaryDeltaMajorVersion3, LATEST_DELTA_DIFF_MAJOR_VERSION);
XCTAssertEqual(SUBinaryDeltaMajorVersion3, SUBinaryDeltaMajorVersionLatest);
BOOL version3DeltaFormatWithLZMASuccess = [self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion3 compressionMode:SPUDeltaCompressionModeLZMA beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
+51 -2
View File
@@ -11,7 +11,7 @@ func makeError(code: SUError, _ description: String) -> NSError {
])
}
func makeAppcast(archivesSourceDir: URL, cacheDirectory cacheDir: URL, keys: PrivateKeys, versions: Set<String>?, maximumDeltas: Int, verbose: Bool) throws -> [String: [ArchiveItem]] {
func makeAppcast(archivesSourceDir: URL, cacheDirectory cacheDir: URL, keys: PrivateKeys, versions: Set<String>?, maximumDeltas: Int, deltaCompressionModeDescription: String, deltaCompressionLevel: UInt8, verbose: Bool) throws -> [String: [ArchiveItem]] {
let comparator = SUStandardVersionComparator()
let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, archivesDestDir: cacheDir, verbose: verbose))
@@ -109,7 +109,56 @@ func makeAppcast(archivesSourceDir: URL, cacheDirectory cacheDir: URL, keys: Pri
}
if !fm.fileExists(atPath: deltaPath.path) {
do {
delta = try DeltaUpdate.create(from: item, to: latestItem, archivePath: deltaPath)
// 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") {
case .orderedSame:
fallthrough
case .orderedDescending:
deltaVersion = .version3
case .orderedAscending:
deltaVersion = .version2
}
} else {
deltaVersion = SUBinaryDeltaMajorVersionDefault
print("Warning: Sparkle.framework version for \(item.appPath.lastPathComponent) (\(item.shortVersion) (\(item.version))) was not found. Falling back to generating delta using default delta version..")
}
let requestedDeltaCompressionMode = deltaCompressionModeFromDescription(deltaCompressionModeDescription, nil)
// Version 2 formats only support bzip2, none, and default options
let deltaCompressionMode: SPUDeltaCompressionMode
if deltaVersion == .version2 {
switch requestedDeltaCompressionMode {
case .LZFSE:
fallthrough
case .LZ4:
fallthrough
case .LZMA:
fallthrough
case .ZLIB:
deltaCompressionMode = .bzip2
print("Warning: Delta compression mode '\(deltaCompressionModeDescription)' was requested but using default compression instead because version 2 delta file from version \(item.version) needs to be generated..")
case SPUDeltaCompressionModeDefault:
fallthrough
case .none:
fallthrough
case .bzip2:
deltaCompressionMode = requestedDeltaCompressionMode
@unknown default:
// This shouldn't happen
print("Warning: failed to parse delta compression mode \(deltaCompressionModeDescription). There is a logic bug in generate_appcast.")
deltaCompressionMode = SPUDeltaCompressionModeDefault
}
} else {
deltaCompressionMode = requestedDeltaCompressionMode
}
delta = try DeltaUpdate.create(from: item, to: latestItem, deltaVersion: deltaVersion, deltaCompressionMode: deltaCompressionMode, deltaCompressionLevel: deltaCompressionLevel, archivePath: deltaPath)
} catch {
print("Could not create delta update", deltaPath.path, error)
continue
+22 -3
View File
@@ -24,10 +24,10 @@ class DeltaUpdate {
return (archiveFileAttributes[.size] as! NSNumber).int64Value
}
class func create(from: ArchiveItem, to: ArchiveItem, archivePath: URL) throws -> DeltaUpdate {
class func create(from: ArchiveItem, to: ArchiveItem, deltaVersion: SUBinaryDeltaMajorVersion, deltaCompressionMode: SPUDeltaCompressionMode, deltaCompressionLevel: UInt8, archivePath: URL) throws -> DeltaUpdate {
var applyDiffError: NSError?
if !createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, SUBinaryDeltaMajorVersionDefault, SPUDeltaCompressionModeDefault, DEFAULT_BZIP2_COMPRESSION_LEVEL, false, &applyDiffError) {
if !createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, deltaVersion, deltaCompressionMode, deltaCompressionLevel, false, &applyDiffError) {
throw applyDiffError!
}
@@ -40,6 +40,7 @@ class ArchiveItem: CustomStringConvertible {
// swiftlint:disable identifier_name
let _shortVersion: String?
let minimumSystemVersion: String
let frameworkVersion: String?
let archivePath: URL
let appPath: URL
let feedURL: URL?
@@ -53,11 +54,12 @@ class ArchiveItem: CustomStringConvertible {
var downloadUrlPrefix: URL?
var releaseNotesURLPrefix: URL?
init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws {
init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, frameworkVersion: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws {
self.version = version
self._shortVersion = shortVersion
self.feedURL = feedURL
self.minimumSystemVersion = minimumSystemVersion ?? "10.11"
self.frameworkVersion = frameworkVersion
self.archivePath = archivePath
self.appPath = appPath
self.supportsDSA = supportsDSA
@@ -106,11 +108,28 @@ class ArchiveItem: CustomStringConvertible {
feedURL = feedURL!.appendingPathComponent("appcast.xml")
}
}
var frameworkVersion: String? = nil
if let appBundle = Bundle(url: appPath), let frameworksURL = appBundle.privateFrameworksURL {
let sparkleBundleURL = frameworksURL.appendingPathComponent("Sparkle").appendingPathExtension("framework")
if let sparkleBundle = Bundle(url: sparkleBundleURL), let infoDictionary = sparkleBundle.infoDictionary {
frameworkVersion = infoDictionary[kCFBundleVersionKey as String] as? String
} else {
// Try legacy SparkleCore framework that was shipping in early 2.0 betas
let sparkleCoreBundleURL = frameworksURL.appendingPathComponent("SparkleCore").appendingPathExtension("framework")
if let sparkleBundle = Bundle(url: sparkleCoreBundleURL), let infoDictionary = sparkleBundle.infoDictionary {
frameworkVersion = infoDictionary[kCFBundleVersionKey as String] as? String
}
}
}
try self.init(version: version,
shortVersion: shortVersion,
feedURL: feedURL,
minimumSystemVersion: infoPlist["LSMinimumSystemVersion"] as? String,
frameworkVersion: frameworkVersion,
publicEdKey: publicEdKey,
supportsDSA: supportsDSA,
appPath: appPath,
+1
View File
@@ -6,6 +6,7 @@
#import "SUUnarchiver.h"
#import "SUBinaryDeltaUnarchiver.h"
#import "SUBinaryDeltaCreate.h"
#import "SUBinaryDeltaCommon.h"
#import "SUSignatures.h"
#import "SPUInstallationType.h"
#import "ed25519.h" // Run `git submodule update --init` if you get an error here
+17 -1
View File
@@ -84,6 +84,12 @@ struct GenerateAppcast: ParsableCommand {
@Option(name: .long, help: ArgumentHelp("The maximum number of delta items to create for the latest update for each minimum required operating system.", valueName: "maximum-deltas"))
var maximumDeltas: Int = DEFAULT_MAXIMUM_DELTAS
@Option(name: .long, help: ArgumentHelp(COMPRESSION_METHOD_ARGUMENT_DESCRIPTION, valueName: "delta-compression"))
var deltaCompression: String = "default"
@Option(name: .long, help: ArgumentHelp(COMPRESSION_LEVEL_ARGUMENT_DESCRIPTION, valueName: "delta-compression-level"))
var deltaCompressionLevel: UInt8 = 0
@Option(name: .long, help: ArgumentHelp("The Sparkle channel name that will be used for generating new updates. By default, no channel is used. Old applications need to be using Sparkle 2 to use this feature.", valueName: "channel-name"))
var channel: String?
@@ -166,6 +172,16 @@ struct GenerateAppcast: ParsableCommand {
guard (informationalUpdateVersions == nil) || (link != nil) else {
throw ValidationError("--link must be specified if --informational-update-versions is specified.")
}
guard deltaCompressionLevel >= 0 && deltaCompressionLevel <= 9 else {
throw ValidationError("Invalid --delta-compression-level value was passed.")
}
var validCompression: ObjCBool = false
let _ = deltaCompressionModeFromDescription(deltaCompression, &validCompression)
if !validCompression.boolValue {
throw ValidationError("Invalid --delta-compression \(deltaCompression) was passed.")
}
}
func run() throws {
@@ -192,7 +208,7 @@ struct GenerateAppcast: ParsableCommand {
let keys = loadPrivateKeys(privateDSAKey, privateEdString)
do {
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, cacheDirectory: GenerateAppcast.cacheDirectory, keys: keys, versions: versions, maximumDeltas: maximumDeltas, verbose: verbose)
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, cacheDirectory: GenerateAppcast.cacheDirectory, keys: keys, versions: versions, maximumDeltas: maximumDeltas, deltaCompressionModeDescription: deltaCompression, deltaCompressionLevel: deltaCompressionLevel, verbose: verbose)
// If a URL prefix was provided, set on the archive items
if downloadURLPrefix != nil || releaseNotesURLPrefix != nil {