mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Add new version 3 binary delta archive format (#2051)
This new format introduces: * A new container format which stores metadata in a way that is more efficient for compression, decompression, and size. Creation time can be 2x faster, apply time can be a few seconds faster, size savings can be 500 KB - couple of MB due to metadata alone. * An array of supported compression formats including lzma, bzip2, zlib and more. We now default to lzma which is as competitive as bzip2 (which we were using in version 2 format) in applying/creation times, but can save several MB on size. * Tracking of files from an old app being replicated in different locations in the new app. This can track unchanged files being renamed and can result in significant savings if the files are large. Version 2 format is still the default. To use version 3, pass --version=3 to BinaryDelta when creating a patch. We will switch the default to version 3 later. generate_appcast support is upcoming.
This commit is contained in:
17 files changed
+2139
-201
No files matched your search
@@ -9,10 +9,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol SPUDeltaArchiveProtocol;
|
||||
@class SPUDeltaArchiveHeader;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
id<SPUDeltaArchiveProtocol> _Nullable SPUDeltaArchiveForReading(NSString *patchFile);
|
||||
id<SPUDeltaArchiveProtocol> _Nullable SPUDeltaArchiveForWriting(NSString *patchFile);
|
||||
// Opens patch file for reading and decodes the archive header
|
||||
id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFile, SPUDeltaArchiveHeader * _Nullable __autoreleasing * _Nullable outHeader);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -8,17 +8,107 @@
|
||||
|
||||
#import "SPUDeltaArchive.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUSparkleDeltaArchive.h"
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
id<SPUDeltaArchiveProtocol> _Nullable SPUDeltaArchiveForReading(NSString *patchFile)
|
||||
SPUDeltaCompressionMode SPUDeltaCompressionModeDefault = (SPUDeltaCompressionMode)UINT8_MAX;
|
||||
|
||||
id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFile, SPUDeltaArchiveHeader * _Nullable __autoreleasing * _Nullable outHeader)
|
||||
{
|
||||
return [[SPUXarDeltaArchive alloc] initWithPatchFileForReading:patchFile];
|
||||
id<SPUDeltaArchiveProtocol> sparkleArchive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForReading:patchFile];
|
||||
|
||||
SPUDeltaArchiveHeader *header = [sparkleArchive readHeader];
|
||||
if (header == nil) {
|
||||
NSError *archiveError = sparkleArchive.error;
|
||||
if (archiveError != nil && [archiveError.domain isEqualToString:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN] && archiveError.code == SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC) {
|
||||
// Retry with XAR archive if the magic value is unexpected
|
||||
[sparkleArchive close];
|
||||
|
||||
id<SPUDeltaArchiveProtocol> xarArchive = [[SPUXarDeltaArchive alloc] initWithPatchFileForReading:patchFile];
|
||||
|
||||
SPUDeltaArchiveHeader *xarHeader = [xarArchive readHeader];
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = xarHeader;
|
||||
}
|
||||
return xarArchive;
|
||||
} else {
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = nil;
|
||||
}
|
||||
return sparkleArchive;
|
||||
}
|
||||
} else {
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = header;
|
||||
}
|
||||
return sparkleArchive;
|
||||
}
|
||||
}
|
||||
|
||||
id<SPUDeltaArchiveProtocol> _Nullable SPUDeltaArchiveForWriting(NSString *patchFile)
|
||||
@implementation SPUDeltaArchiveItem
|
||||
|
||||
@synthesize relativeFilePath = _relativeFilePath;
|
||||
@synthesize physicalFilePath = _physicalFilePath;
|
||||
@synthesize clonedRelativePath = _clonedRelativePath;
|
||||
@synthesize commands = _commands;
|
||||
@synthesize permissions = _permissions;
|
||||
@synthesize context = _context;
|
||||
@synthesize originalMode = _originalMode;
|
||||
@synthesize codedDataLength = _codedDataLength;
|
||||
|
||||
- (instancetype)initWithRelativeFilePath:(NSString *)relativeFilePath commands:(SPUDeltaItemCommands)commands permissions:(uint16_t)permissions
|
||||
{
|
||||
return [[SPUXarDeltaArchive alloc] initWithPatchFileForWriting:patchFile];
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_relativeFilePath = [relativeFilePath copy];
|
||||
_commands = commands;
|
||||
_permissions = permissions;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUDeltaArchiveHeader
|
||||
{
|
||||
unsigned char _beforeTreeHash[CC_SHA1_DIGEST_LENGTH];
|
||||
unsigned char _afterTreeHash[CC_SHA1_DIGEST_LENGTH];
|
||||
}
|
||||
|
||||
@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
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_majorVersion = majorVersion;
|
||||
_minorVersion = minorVersion;
|
||||
|
||||
memcpy(_beforeTreeHash, beforeTreeHash, sizeof(_beforeTreeHash));
|
||||
memcpy(_afterTreeHash, afterTreeHash, sizeof(_afterTreeHash));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||
|
||||
- (unsigned char *)beforeTreeHash
|
||||
{
|
||||
return _beforeTreeHash;
|
||||
}
|
||||
|
||||
- (unsigned char *)afterTreeHash
|
||||
{
|
||||
return _afterTreeHash;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@end
|
||||
@@ -11,41 +11,101 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Attributes for an item we extract/write to the archive
|
||||
typedef NS_ENUM(uint8_t, SPUDeltaFileAttributes) {
|
||||
SPUDeltaFileAttributesDelete = (1u << 0),
|
||||
SPUDeltaFileAttributesExtract = (1u << 1),
|
||||
SPUDeltaFileAttributesModifyPermissions = (1u << 2),
|
||||
SPUDeltaFileAttributesBinaryDiff = (1u << 3),
|
||||
|
||||
// Note: BinaryDiff cannot coexist together with Delete
|
||||
typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
|
||||
SPUDeltaItemCommandEndMarker = 0,
|
||||
SPUDeltaItemCommandDelete = (1u << 0),
|
||||
SPUDeltaItemCommandExtract = (1u << 1),
|
||||
SPUDeltaItemCommandModifyPermissions = (1u << 2),
|
||||
SPUDeltaItemCommandBinaryDiff = (1u << 3),
|
||||
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;
|
||||
|
||||
@property (nonatomic, readonly) uint16_t majorVersion;
|
||||
@property (nonatomic, readonly) uint16_t minorVersion;
|
||||
@property (nonatomic, readonly) unsigned char *beforeTreeHash;
|
||||
@property (nonatomic, readonly) unsigned char *afterTreeHash;
|
||||
|
||||
@end
|
||||
|
||||
// Represents an item we read or write to in our delta archive
|
||||
@interface SPUDeltaArchiveItem : NSObject
|
||||
|
||||
- (instancetype)initWithRelativeFilePath:(NSString *)relativeFilePath commands:(SPUDeltaItemCommands)commands permissions:(uint16_t)permissions;
|
||||
|
||||
@property (nonatomic, readonly) NSString *relativeFilePath;
|
||||
@property (nonatomic, nullable) NSString *physicalFilePath;
|
||||
@property (nonatomic, nullable) NSString *clonedRelativePath;
|
||||
@property (nonatomic, readonly) SPUDeltaItemCommands commands;
|
||||
@property (nonatomic, readonly) uint16_t permissions;
|
||||
|
||||
// Private properties
|
||||
@property (nonatomic, nullable) const void *context;
|
||||
@property (nonatomic) uint16_t originalMode;
|
||||
@property (nonatomic) uint64_t codedDataLength;
|
||||
|
||||
@end
|
||||
|
||||
// A protocol for reading and writing binary delta patches
|
||||
// Operations must be done in order. The header must first be read or written before any other operations.
|
||||
// For reading, file items cannot be extracted out of order.
|
||||
@protocol SPUDeltaArchiveProtocol <NSObject>
|
||||
|
||||
@property (nonatomic, readonly, class) BOOL maySupportSafeExtraction;
|
||||
|
||||
// If non-nil, there was an error with reading or writing data from the archive
|
||||
@property (nonatomic, readonly, nullable) NSError *error;
|
||||
|
||||
// Closes file for reading/writing, called in -dealloc if it's not called manually
|
||||
- (void)close;
|
||||
|
||||
// For reading
|
||||
|
||||
// Retrieves metadata for the archive including major/minor version and expected bundle hashes
|
||||
- (void)getMajorDeltaVersion:(nullable uint16_t *)outMajorDiffVersion minorDeltaVersion:(nullable uint16_t *)outMinorDiffVersion beforeTreeHash:(NSString * _Nullable __autoreleasing * _Nullable)outBeforeTreeHash afterTreeHash:(NSString * _Nullable __autoreleasing * _Nullable)outAfterTreeHash;
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader;
|
||||
|
||||
// Enumerate through items in the patch file and read the path, attributes, permissions (if permission attribute is available), and way to stop enumeration
|
||||
- (BOOL)enumerateItems:(void (^)(const void *item, NSString *relativePath, SPUDeltaFileAttributes attributes, uint16_t permissions, BOOL *stop))itemHandler;
|
||||
- (void)enumerateItems:(void (^)(SPUDeltaArchiveItem *item, BOOL *stop))itemHandler;
|
||||
|
||||
// Extract a file item from the patch file to a destination file
|
||||
- (BOOL)extractItem:(const void *)item destination:(NSString *)destinationPath;
|
||||
// The item's physical file path must be set as a destination
|
||||
- (BOOL)extractItem:(SPUDeltaArchiveItem *)item;
|
||||
|
||||
// ------------
|
||||
|
||||
// For writing
|
||||
|
||||
// Set metadata for archive including major/minor version and expected bundle hashes
|
||||
- (void)setMajorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(NSString *)beforeTreeHash afterTreeHash:(NSString *)afterTreeHash;
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header;
|
||||
|
||||
// Add item to patch file
|
||||
// File path must be provided if there is a extract or binary delta attribute
|
||||
// Physical file path must be provided if there is an extract or binary delta attribute
|
||||
// Permissions are used only if there is a modify permissions attribute
|
||||
- (void)addRelativeFilePath:(NSString *)relativeFilePath realFilePath:(nullable NSString *)filePath attributes:(SPUDeltaFileAttributes)attributes permissions:(uint16_t)permissions;
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item;
|
||||
|
||||
// Finishes encoding items after having added all of them
|
||||
- (void)finishEncodingItems;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SPUSparkleDeltaArchive.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN @"Sparkle Delta Archive"
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC 1
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_COMPRESSION_VALUE 2
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CHUNK_SIZE 3
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP 4
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES 5
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG 6
|
||||
|
||||
/*
|
||||
Modern container format for binary delta archives.
|
||||
|
||||
Delta archive format has four sections which are the header, the relative file path table, the commands, and the data blobs.
|
||||
|
||||
The relative file path table records all the file paths the archive needs to know about.
|
||||
The commands are the operations to be recorded (eg: extract, clone, binary diff, delete).
|
||||
The commands may additionally have more metadata such as file permission modes, relative path indexes in the case of clones, or file sizes for the data blobs.
|
||||
The data blobs contain all file data from extract and binary diff outputs.
|
||||
|
||||
The implementation design of this archive is such that we do not seek backwards or skip ahead to fetch data.
|
||||
We go through the archive when writing or reading from it in a single pass.
|
||||
|
||||
-- UNCOMPRESSED --
|
||||
|
||||
[ HEADER ]
|
||||
magic (length: 4)
|
||||
compression (length: 1)
|
||||
|
||||
-- COMPRESSED --
|
||||
|
||||
[ HEADER (part 2)]
|
||||
majorVersion (length: 2)
|
||||
minorVersion (length: 2)
|
||||
beforeTreeHash (length: 40)
|
||||
afterTreeHash (length: 40)
|
||||
|
||||
[ RELATIVE FILE PATH TABLE ]
|
||||
sizeOfRelativeFilePathTable (length: 8 bytes)
|
||||
List of null terminated path strings joined together (N paths)
|
||||
|
||||
[ COMMANDS ]
|
||||
[ Command ]
|
||||
Set of command types for entry (length: 1 byte)
|
||||
Additional metadata for command
|
||||
(M commands where M <= N paths)
|
||||
(Indexes for commands refer to indexes to relative file path table, excluding extraneous trailing entries in relative path table used for clones)
|
||||
(Last command denotes a null end marker)
|
||||
|
||||
[ DATA BLOBS ]
|
||||
All raw binary data joined together
|
||||
(P number of blobs where P <= M commands)
|
||||
(Indexes for data blobs refer to indexes for a filtered list of applicable commands that have data content)
|
||||
*/
|
||||
@interface SPUSparkleDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,10 +12,11 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Legacy container format for binary delta archives
|
||||
@interface SPUXarDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (nullable instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
|
||||
- (nullable instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+137
-53
@@ -9,7 +9,8 @@
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#include <xar/xar.h>
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include <Availability.h>
|
||||
#import <Availability.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
@@ -37,41 +38,55 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
#define BINARY_DELTA_KEY "binary-delta"
|
||||
#define MODIFY_PERMISSIONS_KEY "mod-permissions"
|
||||
|
||||
// Errors
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN @"Sparkle XAR Archive"
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE 1
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE 2
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE 3
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE 4
|
||||
|
||||
@interface SPUXarDeltaArchive ()
|
||||
|
||||
@property (nonatomic) xar_t x;
|
||||
@property (nonatomic, readonly) int32_t xarMode;
|
||||
@property (nonatomic, readonly) NSMutableDictionary<NSString *, NSValue *> *fileTable;
|
||||
@property (nonatomic, readonly) NSString *patchFile;
|
||||
@property (nonatomic) NSError *error;
|
||||
|
||||
@property (nonatomic, readonly) SPUDeltaCompressionMode writableCompression;
|
||||
@property (nonatomic, readonly) int32_t writableCompressionLevel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUXarDeltaArchive
|
||||
|
||||
@synthesize x = _x;
|
||||
@synthesize xarMode = _xarMode;
|
||||
@synthesize patchFile = _patchFile;
|
||||
@synthesize fileTable = _fileTable;
|
||||
@synthesize writableCompression = _writableCompression;
|
||||
@synthesize writableCompressionLevel = _writableCompressionLevel;
|
||||
@synthesize error = _error;
|
||||
|
||||
- (nullable instancetype)initWithPatchFileForWriting:(NSString *)patchFile
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile compression:(SPUDeltaCompressionMode)compression compressionLevel:(int32_t)compressionLevel
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_x = xar_open(patchFile.fileSystemRepresentation, WRITE);
|
||||
if (_x == NULL) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_patchFile = [patchFile copy];
|
||||
_xarMode = WRITE;
|
||||
_writableCompression = (compression == SPUDeltaCompressionModeDefault ? SPUDeltaCompressionModeBzip2 : compression);
|
||||
_writableCompressionLevel = compressionLevel;
|
||||
_fileTable = [NSMutableDictionary dictionary];
|
||||
xar_opt_set(_x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithPatchFileForReading:(NSString *)patchFile
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_x = xar_open(patchFile.fileSystemRepresentation, READ);
|
||||
if (_x == NULL) {
|
||||
return nil;
|
||||
}
|
||||
_patchFile = [patchFile copy];
|
||||
_xarMode = READ;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -95,8 +110,17 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
return HAS_XAR_GET_SAFE_PATH;
|
||||
}
|
||||
|
||||
- (void)getMajorDeltaVersion:(nullable uint16_t *)outMajorDiffVersion minorDeltaVersion:(nullable uint16_t *)outMinorDiffVersion beforeTreeHash:(NSString * _Nullable __autoreleasing * _Nullable)outBeforeTreeHash afterTreeHash:(NSString * _Nullable __autoreleasing * _Nullable)outAfterTreeHash
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader
|
||||
{
|
||||
NSString *patchFile = self.patchFile;
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, READ);
|
||||
if (x == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for reading: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.x = x;
|
||||
|
||||
uint16_t majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
uint16_t minorDiffVersion = 0;
|
||||
NSString *expectedBeforeHash = nil;
|
||||
@@ -143,33 +167,59 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
}
|
||||
}
|
||||
|
||||
if (outMajorDiffVersion != NULL) {
|
||||
*outMajorDiffVersion = majorDiffVersion;
|
||||
}
|
||||
unsigned char rawExpectedBeforeHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
getRawHashFromDisplayHash(rawExpectedBeforeHash, expectedBeforeHash);
|
||||
|
||||
if (outMinorDiffVersion != NULL) {
|
||||
*outMinorDiffVersion = minorDiffVersion;
|
||||
}
|
||||
unsigned char rawExpectedAfterHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
getRawHashFromDisplayHash(rawExpectedAfterHash, expectedAfterHash);
|
||||
|
||||
if (outBeforeTreeHash != NULL) {
|
||||
*outBeforeTreeHash = expectedBeforeHash;
|
||||
}
|
||||
|
||||
if (outAfterTreeHash != NULL) {
|
||||
*outAfterTreeHash = expectedAfterHash;
|
||||
}
|
||||
return [[SPUDeltaArchiveHeader alloc] initWithMajorVersion:majorDiffVersion minorVersion:minorDiffVersion beforeTreeHash:rawExpectedBeforeHash afterTreeHash:rawExpectedAfterHash];
|
||||
}
|
||||
|
||||
|
||||
- (void)setMajorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(NSString *)beforeTreeHash afterTreeHash:(NSString *)afterTreeHash
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header
|
||||
{
|
||||
xar_subdoc_t attributes = xar_subdoc_new(self.x, BINARY_DELTA_ATTRIBUTES_KEY);
|
||||
NSString *patchFile = self.patchFile;
|
||||
|
||||
xar_subdoc_prop_set(attributes, MAJOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", majorVersion] UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, MINOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", minorVersion] UTF8String]);
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, WRITE);
|
||||
if (x == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for writing: %@", patchFile] }];
|
||||
return;
|
||||
}
|
||||
|
||||
xar_subdoc_prop_set(attributes, BEFORE_TREE_SHA1_KEY, [beforeTreeHash UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, AFTER_TREE_SHA1_KEY, [afterTreeHash UTF8String]);
|
||||
self.x = x;
|
||||
|
||||
SPUDeltaCompressionMode compression = self.writableCompression;
|
||||
int32_t compressionLevel = self.writableCompressionLevel;
|
||||
|
||||
switch (compression) {
|
||||
case SPUDeltaCompressionModeNone:
|
||||
break;
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
|
||||
char buffer[256] = {0};
|
||||
snprintf(buffer, sizeof(buffer) - 1, "%d", compressionLevel);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSIONARG, buffer);
|
||||
|
||||
break;
|
||||
}
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Version 2 patches only support bzip2 compression."] }];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, BINARY_DELTA_ATTRIBUTES_KEY);
|
||||
|
||||
xar_subdoc_prop_set(attributes, MAJOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", header.majorVersion] UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, MINOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", header.minorVersion] UTF8String]);
|
||||
|
||||
xar_subdoc_prop_set(attributes, BEFORE_TREE_SHA1_KEY, [displayHashFromRawHash(header.beforeTreeHash) UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, AFTER_TREE_SHA1_KEY, [displayHashFromRawHash(header.afterTreeHash) UTF8String]);
|
||||
}
|
||||
|
||||
static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTable, xar_t x, NSString *relativePath, NSString *filePath)
|
||||
@@ -218,30 +268,51 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
return lastParent;
|
||||
}
|
||||
|
||||
- (void)addRelativeFilePath:(NSString *)relativeFilePath realFilePath:(nullable NSString *)filePath attributes:(SPUDeltaFileAttributes)attributes permissions:(uint16_t)permissions
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
xar_file_t newFile = _xarAddFile(self.fileTable, self.x, relativeFilePath, filePath);
|
||||
assert(newFile != NULL);
|
||||
if (self.error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesDelete) != 0) {
|
||||
NSString *relativeFilePath = item.relativeFilePath;
|
||||
NSString *filePath = item.physicalFilePath;
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
uint16_t permissions = item.permissions;
|
||||
|
||||
xar_file_t newFile = _xarAddFile(self.fileTable, self.x, relativeFilePath, filePath);
|
||||
if (newFile == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to add xar file entry: %@", relativeFilePath] }];
|
||||
return;
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandDelete) != 0) {
|
||||
xar_prop_set(newFile, DELETE_KEY, "true");
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesExtract) != 0) {
|
||||
if ((commands & SPUDeltaItemCommandExtract) != 0) {
|
||||
xar_prop_set(newFile, EXTRACT_KEY, "true");
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesBinaryDiff) != 0) {
|
||||
if ((commands & SPUDeltaItemCommandBinaryDiff) != 0) {
|
||||
xar_prop_set(newFile, BINARY_DELTA_KEY, "true");
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesModifyPermissions) != 0) {
|
||||
if ((commands & SPUDeltaItemCommandModifyPermissions) != 0) {
|
||||
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [NSString stringWithFormat:@"%u", permissions].UTF8String);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)enumerateItems:(void (^)(const void *, NSString *, SPUDeltaFileAttributes, uint16_t, BOOL *))itemHandler
|
||||
- (void)finishEncodingItems
|
||||
{
|
||||
// Items are already encoded when they are extracted prior
|
||||
}
|
||||
|
||||
- (void)enumerateItems:(void (^)(SPUDeltaArchiveItem *, BOOL *))itemHandler
|
||||
{
|
||||
if (self.error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL exitedEarly = NO;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (xar_file_t file = xar_file_first(self.x, iter); file; file = xar_file_next(iter)) {
|
||||
@@ -268,23 +339,23 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
|
||||
NSString *relativePath = @(pathCString);
|
||||
|
||||
SPUDeltaFileAttributes attributes = 0;
|
||||
SPUDeltaItemCommands commands = 0;
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, DELETE_KEY, &value) == 0) {
|
||||
attributes |= SPUDeltaFileAttributesDelete;
|
||||
commands |= SPUDeltaItemCommandDelete;
|
||||
}
|
||||
}
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, BINARY_DELTA_KEY, &value) == 0) {
|
||||
attributes |= SPUDeltaFileAttributesBinaryDiff;
|
||||
commands |= SPUDeltaItemCommandBinaryDiff;
|
||||
}
|
||||
}
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, EXTRACT_KEY, &value) == 0) {
|
||||
attributes |= SPUDeltaFileAttributesExtract;
|
||||
commands |= SPUDeltaItemCommandExtract;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,26 +363,39 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value) == 0) {
|
||||
attributes |= SPUDeltaFileAttributesModifyPermissions;
|
||||
commands |= SPUDeltaItemCommandModifyPermissions;
|
||||
permissions = (uint16_t)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
itemHandler(file, relativePath, attributes, permissions, &exitedEarly);
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:relativePath commands:commands permissions:permissions];
|
||||
item.context = file;
|
||||
|
||||
itemHandler(item, &exitedEarly);
|
||||
if (exitedEarly) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xar_iter_free(iter);
|
||||
|
||||
return !exitedEarly;
|
||||
}
|
||||
|
||||
- (BOOL)extractItem:(const void *)item destination:(NSString *)destinationPath
|
||||
- (BOOL)extractItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
xar_file_t file = item;
|
||||
return (xar_extract_tofile(self.x, file, destinationPath.fileSystemRepresentation) == 0);
|
||||
if (self.error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
assert(item.physicalFilePath != nil);
|
||||
assert(item.context != NULL);
|
||||
|
||||
xar_file_t file = item.context;
|
||||
if (xar_extract_tofile(self.x, file, item.physicalFilePath.fileSystemRepresentation) != 0) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to extract xar file entry to %@", item.physicalFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -19,13 +19,8 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static BOOL applyBinaryDeltaToFile(id<SPUDeltaArchiveProtocol> archive, const void *item, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
static BOOL applyBinaryDeltaToFile(NSString *patchFile, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
{
|
||||
NSString *patchFile = temporaryFilename(@"apply-binary-delta");
|
||||
if (![archive extractItem:item destination:patchFile]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
BOOL success = (bspatch(4, argv) == 0);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
@@ -34,24 +29,23 @@ static BOOL applyBinaryDeltaToFile(id<SPUDeltaArchiveProtocol> archive, const vo
|
||||
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, void (^progressCallback)(double progress), NSError *__autoreleasing *error)
|
||||
{
|
||||
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveForReading(patchFile);
|
||||
if (archive == nil) {
|
||||
SPUDeltaArchiveHeader *header = nil;
|
||||
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveReadPatchAndHeader(patchFile, &header);
|
||||
if (archive.error != nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to open %@. Giving up.", patchFile] }];
|
||||
*error = archive.error;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
uint16_t minorDiffVersion = 0;
|
||||
|
||||
NSString *expectedBeforeHash = nil;
|
||||
NSString *expectedAfterHash = nil;
|
||||
|
||||
progressCallback(0/6.0);
|
||||
|
||||
[archive getMajorDeltaVersion:&majorDiffVersion minorDeltaVersion:&minorDiffVersion beforeTreeHash:&expectedBeforeHash afterTreeHash:&expectedAfterHash];
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = header.majorVersion;
|
||||
uint16_t minorDiffVersion = header.minorVersion;
|
||||
|
||||
unsigned char *expectedBeforeHash = header.beforeTreeHash;
|
||||
unsigned char *expectedAfterHash = header.afterTreeHash;
|
||||
|
||||
if (majorDiffVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to identify diff-version %u in delta. Giving up.", majorDiffVersion] }];
|
||||
@@ -96,9 +90,9 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
|
||||
progressCallback(1/6.0);
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorDiffVersion);
|
||||
if (!beforeHash) {
|
||||
|
||||
unsigned char beforeHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeWithVersion(beforeHash, source, majorDiffVersion)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -108,12 +102,12 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![beforeHash isEqualToString:expectedBeforeHash]) {
|
||||
if (memcmp(beforeHash, expectedBeforeHash, CC_SHA1_DIGEST_LENGTH) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Source doesn't have expected hash (%@ != %@). Giving up.", expectedBeforeHash, beforeHash] }];
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Source doesn't have expected hash (%@ != %@). Giving up.", displayHashFromRawHash(expectedBeforeHash), displayHashFromRawHash(beforeHash)] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@@ -153,7 +147,14 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
|
||||
if (![archive enumerateItems:^(const void * _Nonnull item, NSString * _Nonnull relativePath, SPUDeltaFileAttributes attributes, uint16_t permissions, BOOL *stop) {
|
||||
// Ensure error is cleared out in advance
|
||||
if (error != NULL) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
[archive enumerateItems:^(SPUDeltaArchiveItem *item, BOOL *stop) {
|
||||
NSString *relativePath = item.relativeFilePath;
|
||||
|
||||
if ([relativePath.pathComponents containsObject:@".."]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path '%@' contains '..' path component", relativePath] }];
|
||||
@@ -189,8 +190,8 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
|
||||
// Files that have no property set that we check for will get ignored
|
||||
// This is important because they aren't part of the delta, just part of the directory structure
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesDelete) != 0) {
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
if ((commands & SPUDeltaItemCommandDelete) != 0) {
|
||||
if (!removeTree(destinationFilePath)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -205,8 +206,51 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
removedFile = YES;
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesBinaryDiff) != 0) {
|
||||
if (!applyBinaryDeltaToFile(archive, item, sourceFilePath, destinationFilePath)) {
|
||||
if ((commands & SPUDeltaItemCommandClone) != 0) {
|
||||
NSString *clonedRelativePath = item.clonedRelativePath;
|
||||
if ([clonedRelativePath.pathComponents containsObject:@".."]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone '%@' contains '..' path component", clonedRelativePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *clonedOriginalPath = [source stringByAppendingPathComponent:clonedRelativePath];
|
||||
|
||||
NSError *copyError = nil;
|
||||
if (![fileManager copyItemAtPath:clonedOriginalPath toPath:destinationFilePath error:©Error]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = copyError;
|
||||
}
|
||||
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n✂️ %s %s -> %s", VERBOSE_CLONED, [clonedRelativePath fileSystemRepresentation], [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
} else if ((commands & SPUDeltaItemCommandBinaryDiff) != 0) {
|
||||
NSString *tempDiffFile = temporaryFilename(@"apply-binary-delta");
|
||||
item.physicalFilePath = tempDiffFile;
|
||||
|
||||
if (![archive extractItem:item]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to extract diffed file to %@", tempDiffFile], NSUnderlyingErrorKey: (NSError * _Nonnull)archive.error }];
|
||||
}
|
||||
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!applyBinaryDeltaToFile(tempDiffFile, sourceFilePath, destinationFilePath)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -220,13 +264,14 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n🔨 %s %s", VERBOSE_PATCHED, [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
} else if ((attributes & SPUDeltaFileAttributesExtract) != 0) { // extract and permission modifications don't coexist
|
||||
if (![archive extractItem:item destination:destinationFilePath]) {
|
||||
} else if ((commands & SPUDeltaItemCommandExtract) != 0) { // extract and permission modifications don't coexist
|
||||
item.physicalFilePath = destinationFilePath;
|
||||
if (![archive extractItem:item]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to extract file to %@", destinationFilePath] }];
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to extract file to %@", destinationFilePath], NSUnderlyingErrorKey: (NSError * _Nonnull)archive.error }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
@@ -243,8 +288,8 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_DELETED, [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ((attributes & SPUDeltaFileAttributesModifyPermissions) != 0) {
|
||||
mode_t mode = (mode_t)permissions;
|
||||
if ((commands & SPUDeltaItemCommandModifyPermissions) != 0) {
|
||||
mode_t mode = (mode_t)item.permissions;
|
||||
if (!modifyPermissions(destinationFilePath, mode)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -260,19 +305,30 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
fprintf(stderr, "\n👮 %s %s (0%o)", VERBOSE_MODIFIED, [relativePath fileSystemRepresentation], mode);
|
||||
}
|
||||
}
|
||||
}]) {
|
||||
return NO;
|
||||
}
|
||||
}];
|
||||
|
||||
[archive close];
|
||||
|
||||
// Set error from enumerating items if we have encountered an error and haven't set it yet
|
||||
NSError *archiveError = archive.error;
|
||||
if (archiveError != nil) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL && *error == nil) {
|
||||
*error = archiveError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(5/6.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nVerifying destination...");
|
||||
}
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorDiffVersion);
|
||||
if (afterHash == nil) {
|
||||
|
||||
unsigned char afterHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeWithVersion(afterHash, destination, majorDiffVersion)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -282,12 +338,12 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![afterHash isEqualToString:expectedAfterHash]) {
|
||||
if (memcmp(afterHash, expectedAfterHash, CC_SHA1_DIGEST_LENGTH) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Destination doesn't have expected hash (%@ != %@). Giving up.", expectedAfterHash, afterHash] }];
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Destination doesn't have expected hash (%@ != %@). Giving up.", displayHashFromRawHash(expectedAfterHash), displayHashFromRawHash(afterHash)] }];
|
||||
}
|
||||
removeTree(destination);
|
||||
return NO;
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
|
||||
#define PERMISSION_FLAGS (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)
|
||||
|
||||
#define IS_VALID_PERMISSIONS(mode) \
|
||||
(((mode & PERMISSION_FLAGS) == 0755) || ((mode & PERMISSION_FLAGS) == 0644))
|
||||
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY "com.apple.cs.CodeDirectory"
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY "com.apple.cs.CodeRequirements"
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY "com.apple.cs.CodeSignature"
|
||||
@@ -29,25 +26,32 @@
|
||||
#define VERBOSE_PATCHED "Patched" // file is patched when applying a patch
|
||||
#define VERBOSE_UPDATED "Updated" // file's contents are updated
|
||||
#define VERBOSE_MODIFIED "Modified" // file's metadata is modified
|
||||
#define VERBOSE_CLONED "Cloned" // file is cloned in content from a differently named file
|
||||
|
||||
#define MAJOR_VERSION_IS_AT_LEAST(actualMajor, expectedMajor) (actualMajor >= expectedMajor)
|
||||
|
||||
// Each major version will be assigned a name of a color
|
||||
// Changes that break backwards compatibility will have different major versions
|
||||
// Changes that affect creating but not applying patches will have different minor versions
|
||||
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
|
||||
{
|
||||
// Note: support for creating or applying version 1 deltas have been removed
|
||||
SUBinaryDeltaMajorVersion1 = 1,
|
||||
SUBinaryDeltaMajorVersion2 = 2
|
||||
SUBinaryDeltaMajorVersion2 = 2,
|
||||
SUBinaryDeltaMajorVersion3 = 3
|
||||
};
|
||||
|
||||
// For Swift access
|
||||
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault;
|
||||
|
||||
#define FIRST_DELTA_DIFF_MAJOR_VERSION SUBinaryDeltaMajorVersion1
|
||||
#define FIRST_SUPPORTED_DELTA_MAJOR_VERSION SUBinaryDeltaMajorVersion2
|
||||
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBinaryDeltaMajorVersion2
|
||||
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBinaryDeltaMajorVersion3
|
||||
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
BOOL getRawHashOfTreeWithVersion(unsigned char *hashBuffer, NSString *path, uint16_t majorVersion);
|
||||
BOOL getRawHashOfTreeAndFileTablesWithVersion(unsigned char *hashBuffer, NSString *path, uint16_t majorVersion, NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *hashToFileKeyDictionary, NSMutableDictionary<NSString *, NSData *> *fileKeyToHashDictionary);
|
||||
NSString *displayHashFromRawHash(const unsigned char *hash);
|
||||
void getRawHashFromDisplayHash(unsigned char *hash, NSString *hexHash);
|
||||
extern NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion);
|
||||
extern NSString *hashOfTree(NSString *path);
|
||||
extern BOOL removeTree(NSString *path);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault = SUBinaryDeltaMajorVersion2;
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll((*a)->fts_name, (*b)->fts_name);
|
||||
@@ -45,6 +47,8 @@ uint16_t latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersio
|
||||
return 2;
|
||||
case SUBinaryDeltaMajorVersion2:
|
||||
return 3;
|
||||
case SUBinaryDeltaMajorVersion3:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -136,18 +140,23 @@ static BOOL _hashOfFileContents(unsigned char *hash, FTSENT *ent)
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSString *hashOfTreeWithVersion(NSString *path, uint16_t __unused majorVersion)
|
||||
BOOL getRawHashOfTreeWithVersion(unsigned char *hashBuffer, NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
return getRawHashOfTreeAndFileTablesWithVersion(hashBuffer, path, majorVersion, nil, nil);
|
||||
}
|
||||
|
||||
BOOL getRawHashOfTreeAndFileTablesWithVersion(unsigned char *hashBuffer, NSString *path, uint16_t __unused majorVersion, NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *hashToFileKeyDictionary, NSMutableDictionary<NSString *, NSData *> *fileKeyToHashDictionary)
|
||||
{
|
||||
char pathBuffer[PATH_MAX] = { 0 };
|
||||
if (![path getFileSystemRepresentation:pathBuffer maxLength:sizeof(pathBuffer)]) {
|
||||
return nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
char *const sourcePaths[] = { pathBuffer, 0 };
|
||||
FTS *fts = fts_open(sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
CC_SHA1_CTX hashContext;
|
||||
@@ -167,9 +176,25 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t __unused majorVersion)
|
||||
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
if (!_hashOfFileContents(fileHash, ent)) {
|
||||
return nil;
|
||||
return NO;
|
||||
}
|
||||
CC_SHA1_Update(&hashContext, fileHash, sizeof(fileHash));
|
||||
|
||||
// For file hash tables we only track regular files
|
||||
if (ent->fts_info == FTS_F) {
|
||||
NSData *hashKey = [NSData dataWithBytes:fileHash length:sizeof(fileHash)];
|
||||
|
||||
if (hashToFileKeyDictionary != nil) {
|
||||
if (hashToFileKeyDictionary[hashKey] == nil) {
|
||||
hashToFileKeyDictionary[hashKey] = [NSMutableArray array];
|
||||
}
|
||||
[hashToFileKeyDictionary[hashKey] addObject:relativePath];
|
||||
}
|
||||
|
||||
if (fileKeyToHashDictionary != nil) {
|
||||
fileKeyToHashDictionary[relativePath] = hashKey;
|
||||
}
|
||||
}
|
||||
|
||||
const char *relativePathBytes = [relativePath fileSystemRepresentation];
|
||||
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
|
||||
@@ -188,17 +213,43 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t __unused majorVersion)
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
CC_SHA1_Final(hashBuffer, &hashContext);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
char hexHash[CC_SHA1_DIGEST_LENGTH * 2 + 1];
|
||||
size_t i;
|
||||
for (i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
|
||||
void getRawHashFromDisplayHash(unsigned char *hash, NSString *hexHash)
|
||||
{
|
||||
const char *hexString = hexHash.UTF8String;
|
||||
if (hexString == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t blockIndex = 0; blockIndex < CC_SHA1_DIGEST_LENGTH; blockIndex++) {
|
||||
const char *currentBlock = hexString + blockIndex * 2;
|
||||
char convertedBlock[3] = {currentBlock[0], currentBlock[1], '\0'};
|
||||
hash[blockIndex] = (unsigned char)strtol(convertedBlock, NULL, 16);
|
||||
}
|
||||
}
|
||||
|
||||
NSString *displayHashFromRawHash(const unsigned char *hash)
|
||||
{
|
||||
char hexHash[CC_SHA1_DIGEST_LENGTH * 2 + 1] = {0};
|
||||
for (size_t i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
|
||||
sprintf(hexHash + i * 2, "%02x", hash[i]);
|
||||
|
||||
}
|
||||
return @(hexHash);
|
||||
}
|
||||
|
||||
NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
|
||||
if (!getRawHashOfTreeWithVersion(hash, path, majorVersion)) {
|
||||
return nil;
|
||||
}
|
||||
return displayHashFromRawHash(hash);
|
||||
}
|
||||
|
||||
extern NSString *hashOfTree(NSString *path)
|
||||
{
|
||||
return hashOfTreeWithVersion(path, LATEST_DELTA_DIFF_MAJOR_VERSION);
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
#define SUBINARYDELTACREATE_H
|
||||
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
|
||||
@class NSString;
|
||||
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose, NSError * __autoreleasing *error);
|
||||
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, int32_t compressionLevel, BOOL verbose, NSError * __autoreleasing *error);
|
||||
|
||||
#endif
|
||||
@@ -10,7 +10,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUDeltaArchive.h"
|
||||
#import "SPUSparkleDeltaArchive.h"
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
@@ -90,15 +91,6 @@ static NSDictionary *infoForFile(FTSENT *ent)
|
||||
INFO_SIZE_KEY: @(size) };
|
||||
}
|
||||
|
||||
static bool isSymLink(const FTSENT *ent)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL)
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool aclExists(const FTSENT *ent)
|
||||
{
|
||||
// macOS does not currently support ACLs for symlinks
|
||||
@@ -193,7 +185,7 @@ static BOOL shouldSkipDeltaCompression(NSDictionary *originalInfo, NSDictionary
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldDeleteThenExtract(NSDictionary *originalInfo, NSDictionary *newInfo)
|
||||
static BOOL shouldDeleteThenExtract(NSDictionary *originalInfo, NSDictionary *newInfo, SUBinaryDeltaMajorVersion majorVersion)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
@@ -202,6 +194,14 @@ 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;
|
||||
}
|
||||
@@ -250,7 +250,54 @@ static BOOL shouldChangePermissions(NSDictionary *originalInfo, NSDictionary *ne
|
||||
return YES;
|
||||
}
|
||||
|
||||
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose, NSError *__autoreleasing *error)
|
||||
#define MIN_SIZE_FOR_CLONE 4096
|
||||
static NSString *cloneableRelativePath(NSDictionary<NSString *, NSData *> *afterFileKeyToHashDictionary, NSDictionary<NSData *, NSArray<NSString *> *> *beforeHashToFileKeyDictionary, NSDictionary *originalTreeState, NSDictionary *newInfo, NSString *key, NSNumber * __autoreleasing *outPermissions)
|
||||
{
|
||||
if (afterFileKeyToHashDictionary == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Avoid clones for small files. Small files can compress very well, sometimes better than tracking clones.
|
||||
if ([(NSNumber *)newInfo[INFO_SIZE_KEY] unsignedLongLongValue] <= MIN_SIZE_FOR_CLONE) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSData *keyHash = afterFileKeyToHashDictionary[key];
|
||||
if (keyHash == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
for (NSString *oldRelativePath in beforeHashToFileKeyDictionary[keyHash]) {
|
||||
NSDictionary *oldCloneInfo = originalTreeState[oldRelativePath];
|
||||
if (oldCloneInfo == nil) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ([(NSNumber *)oldCloneInfo[INFO_TYPE_KEY] unsignedShortValue] != FTS_F || [(NSNumber *)newInfo[INFO_TYPE_KEY] unsignedShortValue] != FTS_F) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *clonePath = oldCloneInfo[INFO_PATH_KEY];
|
||||
NSString *newPath = newInfo[INFO_PATH_KEY];
|
||||
|
||||
if (![[NSFileManager defaultManager] contentsEqualAtPath:clonePath andPath:newPath]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSNumber *newPermissions = newInfo[INFO_PERMISSIONS_KEY];
|
||||
if ([(NSNumber *)oldCloneInfo[INFO_PERMISSIONS_KEY] unsignedShortValue] != [newPermissions unsignedShortValue]) {
|
||||
if (outPermissions != NULL) {
|
||||
*outPermissions = newPermissions;
|
||||
}
|
||||
}
|
||||
|
||||
return oldRelativePath;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, int32_t compressionLevel, BOOL verbose, NSError *__autoreleasing *error)
|
||||
{
|
||||
assert(source);
|
||||
assert(destination);
|
||||
@@ -328,9 +375,10 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorVersion);
|
||||
|
||||
if (!beforeHash) {
|
||||
NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *beforeHashToFileKeyDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;
|
||||
|
||||
unsigned char beforeHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeAndFileTablesWithVersion(beforeHash, source, majorVersion, beforeHashToFileKeyDictionary, nil)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -390,23 +438,10 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
return NO;
|
||||
}
|
||||
|
||||
// We should validate permissions and ACLs even if we don't store the info in the diff in the case of ACLs,
|
||||
// or in the case of permissions if the patch version is 1
|
||||
|
||||
// We should validate ACLs even if we don't store the info in the diff in the case of ACLs
|
||||
// We should also not allow files with code signed extended attributes since Apple doesn't recommend inserting these
|
||||
// inside an application, and since we don't preserve extended attribitutes anyway
|
||||
|
||||
mode_t permissions = [(NSNumber*)info[INFO_PERMISSIONS_KEY] unsignedShortValue];
|
||||
if (!isSymLink(ent) && !IS_VALID_PERMISSIONS(permissions)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Invalid file permissions after-tree on file %@ (only permissions with modes 0755 and 0644 are supported)", @(ent->fts_path)] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (aclExists(ent)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -449,8 +484,10 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorVersion);
|
||||
if (!afterHash) {
|
||||
NSMutableDictionary<NSString *, NSData *> *afterFileKeyToHashDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;
|
||||
|
||||
unsigned char afterHash[CC_SHA1_DIGEST_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeAndFileTablesWithVersion(afterHash, destination, majorVersion, nil, afterFileKeyToHashDictionary)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -469,18 +506,25 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
fprintf(stderr, "\nWriting to temporary file %s...", [temporaryFile fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveForWriting(temporaryFile);
|
||||
if (archive == nil) {
|
||||
id<SPUDeltaArchiveProtocol> archive;
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion3) {
|
||||
archive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile compression:compression compressionLevel:compressionLevel];
|
||||
} else {
|
||||
archive = [[SPUXarDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile compression:compression compressionLevel:compressionLevel];
|
||||
}
|
||||
|
||||
SPUDeltaArchiveHeader *header = [[SPUDeltaArchiveHeader alloc] initWithMajorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeHash afterTreeHash:afterHash];
|
||||
|
||||
[archive writeHeader:header];
|
||||
if (archive.error != nil) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write to %@", temporaryFile] }];
|
||||
*error = archive.error;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
[archive setMajorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeHash afterTreeHash:afterHash];
|
||||
|
||||
NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init];
|
||||
NSMutableArray *deltaOperations = [NSMutableArray array];
|
||||
@@ -500,7 +544,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
id value = [newTreeState valueForKey:key];
|
||||
|
||||
if ([(NSObject *)value isEqual:[NSNull null]]) {
|
||||
[archive addRelativeFilePath:key realFilePath:nil attributes:SPUDeltaFileAttributesDelete permissions:0];
|
||||
[archive addItem:[[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:key commands:SPUDeltaItemCommandDelete permissions:0]];
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_REMOVED, [key fileSystemRepresentation]);
|
||||
@@ -513,24 +557,52 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
if (shouldSkipDeltaCompression(originalInfo, newInfo)) {
|
||||
if (shouldSkipExtracting(originalInfo, newInfo)) {
|
||||
if (shouldChangePermissions(originalInfo, newInfo)) {
|
||||
[archive addRelativeFilePath:key realFilePath:nil attributes:SPUDeltaFileAttributesModifyPermissions permissions:[(NSNumber *)newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]];
|
||||
[archive addItem:[[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:key commands:SPUDeltaItemCommandModifyPermissions permissions:[(NSNumber *)newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]]];
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o -> 0%o)", VERBOSE_MODIFIED, [key fileSystemRepresentation], [(NSNumber *)originalInfo[INFO_PERMISSIONS_KEY] unsignedShortValue], [(NSNumber *)newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NSString *path = [destination stringByAppendingPathComponent:key];
|
||||
|
||||
SPUDeltaFileAttributes attributes = shouldDeleteThenExtract(originalInfo, newInfo) ? (SPUDeltaFileAttributesDelete | SPUDeltaFileAttributesExtract) : SPUDeltaFileAttributesExtract;
|
||||
|
||||
[archive addRelativeFilePath:key realFilePath:path attributes:attributes permissions:0];
|
||||
// Check if the new file can be cloned from an old existing one located at a different path
|
||||
NSNumber *newPermissionsFromClone = nil;
|
||||
NSString *clonedRelativePath = cloneableRelativePath(afterFileKeyToHashDictionary, beforeHashToFileKeyDictionary, originalTreeState, newInfo, key, &newPermissionsFromClone);
|
||||
if (clonedRelativePath != nil) {
|
||||
SPUDeltaItemCommands commands = SPUDeltaItemCommandClone;
|
||||
if (shouldDeleteThenExtract(originalInfo, newInfo, majorVersion)) {
|
||||
commands |= SPUDeltaItemCommandDelete;
|
||||
}
|
||||
if (newPermissionsFromClone != nil) {
|
||||
commands |= SPUDeltaItemCommandModifyPermissions;
|
||||
}
|
||||
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:key commands:commands permissions:newPermissionsFromClone.unsignedShortValue];
|
||||
// Physical path for clones points to the old file
|
||||
item.physicalFilePath = [source stringByAppendingPathComponent:clonedRelativePath];
|
||||
item.clonedRelativePath = clonedRelativePath;
|
||||
|
||||
[archive addItem:item];
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n✂️ %s %s -> %s", VERBOSE_CLONED, [clonedRelativePath fileSystemRepresentation], [key fileSystemRepresentation]);
|
||||
}
|
||||
} else {
|
||||
// Otherwise add a new file
|
||||
NSString *path = [destination stringByAppendingPathComponent:key];
|
||||
|
||||
SPUDeltaItemCommands commands = shouldDeleteThenExtract(originalInfo, newInfo, majorVersion) ? (SPUDeltaItemCommandDelete | SPUDeltaItemCommandExtract) : SPUDeltaItemCommandExtract;
|
||||
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:key commands:commands permissions:0];
|
||||
item.physicalFilePath = path;
|
||||
|
||||
[archive addItem:item];
|
||||
|
||||
if (verbose) {
|
||||
if (originalInfo) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [key fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n✅ %s %s", VERBOSE_ADDED, [key fileSystemRepresentation]);
|
||||
if (verbose) {
|
||||
if (originalInfo) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [key fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n✅ %s %s", VERBOSE_ADDED, [key fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -547,6 +619,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
|
||||
[deltaQueue waitUntilAllOperationsAreFinished];
|
||||
|
||||
BOOL deltaOperationsFailed = NO;
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
if (resultPath == nil) {
|
||||
@@ -556,7 +629,8 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to create patch from source %@ and destination %@", operation.relativePath, resultPath] }];
|
||||
}
|
||||
return NO;
|
||||
deltaOperationsFailed = YES;
|
||||
break;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
@@ -566,11 +640,12 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
NSNumber *permissions = operation.permissions;
|
||||
NSString *relativePath = operation.relativePath;
|
||||
|
||||
SPUDeltaFileAttributes attributes = (permissions != nil) ? (SPUDeltaFileAttributesBinaryDiff | SPUDeltaFileAttributesModifyPermissions) : SPUDeltaFileAttributesBinaryDiff;
|
||||
SPUDeltaItemCommands commands = (permissions != nil) ? (SPUDeltaItemCommandBinaryDiff | SPUDeltaItemCommandModifyPermissions) : SPUDeltaItemCommandBinaryDiff;
|
||||
|
||||
[archive addRelativeFilePath:relativePath realFilePath:resultPath attributes:attributes permissions:permissions.unsignedShortValue];
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:relativePath commands:commands permissions:permissions.unsignedShortValue];
|
||||
item.physicalFilePath = resultPath;
|
||||
|
||||
unlink(resultPath.fileSystemRepresentation);
|
||||
[archive addItem:item];
|
||||
|
||||
if (permissions != nil) {
|
||||
if (verbose) {
|
||||
@@ -578,8 +653,36 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!deltaOperationsFailed) {
|
||||
[archive finishEncodingItems];
|
||||
}
|
||||
|
||||
[archive close];
|
||||
|
||||
// Clean up operations after the archive has finished encoding
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
if (resultPath != nil) {
|
||||
unlink(resultPath.fileSystemRepresentation);
|
||||
}
|
||||
}
|
||||
|
||||
if (deltaOperationsFailed) {
|
||||
// We already set an error so let's bail
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *archiveError = archive.error;
|
||||
if (archiveError != nil) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = archiveError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSFileManager *filemgr;
|
||||
filemgr = [NSFileManager defaultManager];
|
||||
|
||||
@@ -73,7 +73,7 @@ static BOOL runCreateCommand(NSString *programName, NSArray<NSString *> *args)
|
||||
|
||||
SUBinaryDeltaMajorVersion patchVersion =
|
||||
!versionComponents ?
|
||||
LATEST_DELTA_DIFF_MAJOR_VERSION :
|
||||
SUBinaryDeltaMajorVersionDefault :
|
||||
(SUBinaryDeltaMajorVersion)[[versionComponents[1] componentsSeparatedByString:@"."][0] intValue]; // ignore minor version if provided
|
||||
|
||||
if (patchVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
@@ -119,9 +119,37 @@ static BOOL runCreateCommand(NSString *programName, NSArray<NSString *> *args)
|
||||
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, verbose, &createDiffError)) {
|
||||
if (!createBinaryDelta(sourcePath, destPath, patchPath, patchVersion, compression, compressionLevel, verbose, &createDiffError)) {
|
||||
fprintf(stderr, "%s\n", [createDiffError.localizedDescription UTF8String]);
|
||||
return NO;
|
||||
}
|
||||
@@ -192,15 +220,15 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args)
|
||||
uint16_t majorDiffVersion = 0;
|
||||
uint16_t minorDiffVersion = 0;
|
||||
|
||||
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveForReading(patchFile);
|
||||
if (archive == nil) {
|
||||
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;
|
||||
}
|
||||
|
||||
[archive getMajorDeltaVersion:&majorDiffVersion minorDeltaVersion:&minorDiffVersion beforeTreeHash:NULL afterTreeHash:NULL];
|
||||
|
||||
if (majorDiffVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
if (header.majorVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "Unable to retrieve version information from patch %s\n", [patchFile fileSystemRepresentation]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright © 2019 Sparkle Project. All rights reserved.
|
||||
|
||||
#include "bsdiff-Shared.xcconfig"
|
||||
|
||||
// Disable asserts for performance
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) NDEBUG=1
|
||||
@@ -215,6 +215,9 @@
|
||||
725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 725602D31C83551C00DAA70E /* SUApplicationInfo.h */; };
|
||||
725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SUApplicationInfo.m */; };
|
||||
725B3A82263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml in Resources */ = {isa = PBXBuildFile; fileRef = 725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */; };
|
||||
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 */; };
|
||||
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 */; };
|
||||
@@ -328,6 +331,10 @@
|
||||
728337A61C9E6FF40085AA99 /* SPUProbeInstallStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 728337A41C9E6FF40085AA99 /* SPUProbeInstallStatus.h */; };
|
||||
728337A71C9E6FF40085AA99 /* SPUProbeInstallStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 728337A51C9E6FF40085AA99 /* SPUProbeInstallStatus.m */; };
|
||||
728638ED1CAF50CE00783084 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
|
||||
728ED34A277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
|
||||
728ED34B277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
|
||||
728ED34C277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
|
||||
728ED34D277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
|
||||
729051E41DC82AC0003DEA7F /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
7293A1AE1CEE933800B957A7 /* SPUURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7293A1AC1CEE933800B957A7 /* SPUURLRequest.h */; };
|
||||
7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; };
|
||||
@@ -1136,6 +1143,7 @@
|
||||
725602D41C83551C00DAA70E /* SUApplicationInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUApplicationInfo.m; sourceTree = "<group>"; };
|
||||
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; };
|
||||
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>"; };
|
||||
@@ -1239,6 +1247,8 @@
|
||||
728337A41C9E6FF40085AA99 /* SPUProbeInstallStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUProbeInstallStatus.h; sourceTree = "<group>"; };
|
||||
728337A51C9E6FF40085AA99 /* SPUProbeInstallStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUProbeInstallStatus.m; sourceTree = "<group>"; };
|
||||
728638EE1CAF589C00783084 /* ConfigDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigDownloader.xcconfig; sourceTree = "<group>"; };
|
||||
728ED348277DA23400D9238F /* SPUSparkleDeltaArchive.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SPUSparkleDeltaArchive.h; path = Autoupdate/SPUSparkleDeltaArchive.h; sourceTree = SOURCE_ROOT; };
|
||||
728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SPUSparkleDeltaArchive.m; path = Autoupdate/SPUSparkleDeltaArchive.m; sourceTree = SOURCE_ROOT; };
|
||||
7293A1AC1CEE933800B957A7 /* SPUURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUURLRequest.h; sourceTree = "<group>"; };
|
||||
7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUURLRequest.m; sourceTree = "<group>"; };
|
||||
729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUpdateValidator.h; path = Sparkle/SUUpdateValidator.h; sourceTree = SOURCE_ROOT; };
|
||||
@@ -1407,6 +1417,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
725B81FB2781CD930041746F /* libcompression.tbd in Frameworks */,
|
||||
5A06357323FE333600478A72 /* libed25519.a in Frameworks */,
|
||||
EA1E281822B645CE004AA304 /* libbsdiff.a in Frameworks */,
|
||||
14732BD119610A1200593899 /* AppKit.framework in Frameworks */,
|
||||
@@ -1500,6 +1511,7 @@
|
||||
EA1E281722B645AE004AA304 /* libbsdiff.a in Frameworks */,
|
||||
7267E5C91D3D8C4300D1BF90 /* CoreServices.framework in Frameworks */,
|
||||
7267E5CA1D3D8C4800D1BF90 /* Foundation.framework in Frameworks */,
|
||||
725B81FA2781AEAF0041746F /* libcompression.tbd in Frameworks */,
|
||||
5A06357023FE332300478A72 /* libed25519.a in Frameworks */,
|
||||
7267E5D61D3D8D3500D1BF90 /* libbz2.tbd in Frameworks */,
|
||||
7267E5D51D3D8D2800D1BF90 /* libxar.tbd in Frameworks */,
|
||||
@@ -1520,6 +1532,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
725B81FC2781CDC20041746F /* libcompression.tbd in Frameworks */,
|
||||
1495006F195FCE1800BC5B5B /* Foundation.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -1602,6 +1615,7 @@
|
||||
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
725B81F92781AEA40041746F /* libcompression.tbd */,
|
||||
0867D6A5FE840307C02AAC07 /* AppKit.framework */,
|
||||
721BC2081D17A553002BC71E /* Carbon.framework */,
|
||||
525A278F133D6AE900FD8D70 /* Cocoa.framework */,
|
||||
@@ -1776,6 +1790,8 @@
|
||||
725EE481277BF17A00D820CE /* SPUDeltaArchiveProtocol.h */,
|
||||
725EE484277D375F00D820CE /* SPUDeltaArchive.h */,
|
||||
725EE485277D375F00D820CE /* SPUDeltaArchive.m */,
|
||||
728ED348277DA23400D9238F /* SPUSparkleDeltaArchive.h */,
|
||||
728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */,
|
||||
725EE47E277BF13A00D820CE /* SPUXarDeltaArchive.h */,
|
||||
725EE47F277BF13B00D820CE /* SPUXarDeltaArchive.m */,
|
||||
7267E5741D3D895B00D1BF90 /* SUBinaryDeltaTool.m */,
|
||||
@@ -3173,6 +3189,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
725EE482277BF44A00D820CE /* SPUXarDeltaArchive.m in Sources */,
|
||||
728ED34C277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */,
|
||||
7267E5761D3D895B00D1BF90 /* SUBinaryDeltaApply.m in Sources */,
|
||||
725EE487277D376000D820CE /* SPUDeltaArchive.m in Sources */,
|
||||
7267E5781D3D895B00D1BF90 /* SUBinaryDeltaCommon.m in Sources */,
|
||||
@@ -3197,6 +3214,7 @@
|
||||
7267E5EE1D3D915900D1BF90 /* SUBinaryDeltaApply.m in Sources */,
|
||||
7267E5EF1D3D915900D1BF90 /* SUBinaryDeltaCommon.m in Sources */,
|
||||
7267E5F01D3D915900D1BF90 /* SUBinaryDeltaCreate.m in Sources */,
|
||||
728ED34B277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */,
|
||||
142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */,
|
||||
7267E5F11D3D917A00D1BF90 /* SUBinaryDeltaUnarchiver.m in Sources */,
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */,
|
||||
@@ -3249,6 +3267,7 @@
|
||||
7205C44E1E1304CE00E370AE /* Signatures.swift in Sources */,
|
||||
7205C44F1E1304CE00E370AE /* FeedXML.swift in Sources */,
|
||||
7205C4411E13049400E370AE /* main.swift in Sources */,
|
||||
728ED34D277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */,
|
||||
7205C45F1E13066F00E370AE /* SUBinaryDeltaApply.m in Sources */,
|
||||
7205C4621E1306A600E370AE /* SUBinaryDeltaCommon.m in Sources */,
|
||||
FA30773F24CBC3E9007BA37D /* URL+Hashing.swift in Sources */,
|
||||
@@ -3371,6 +3390,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
725EE480277BF13B00D820CE /* SPUXarDeltaArchive.m in Sources */,
|
||||
728ED34A277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */,
|
||||
72EF30C42675CFA1008CE987 /* SPUAppcastItemState.m in Sources */,
|
||||
72EF30C52675CFA1008CE987 /* SPUAppcastItemStateResolver.m in Sources */,
|
||||
72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */,
|
||||
|
||||
+269
-11
@@ -46,7 +46,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
XCTAssert(YES, @"Pass");
|
||||
}
|
||||
|
||||
- (BOOL)createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)majorVersion beforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
|
||||
- (BOOL)createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)majorVersion compressionMode:(SPUDeltaCompressionMode)compressionMode beforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
|
||||
{
|
||||
NSString *sourceDirectory = temporaryDirectory(@"Spąrkle_temp1エンジン");
|
||||
NSString *destinationDirectory = temporaryDirectory(@"Spąrkle_temp2エンジン");
|
||||
@@ -65,7 +65,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}
|
||||
|
||||
NSError *createDiffError = nil;
|
||||
BOOL createdDiff = createBinaryDelta(sourceDirectory, destinationDirectory, diffFile, majorVersion, NO, &createDiffError);
|
||||
BOOL createdDiff = createBinaryDelta(sourceDirectory, destinationDirectory, diffFile, majorVersion, compressionMode, DEFAULT_BZIP2_COMPRESSION_LEVEL, NO, &createDiffError);
|
||||
if (!createdDiff) {
|
||||
NSLog(@"Creating binary diff failed with error: %@", createDiffError);
|
||||
} else if (afterDiffHandler != nil) {
|
||||
@@ -92,7 +92,17 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
|
||||
- (BOOL)createAndApplyPatchWithBeforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
|
||||
{
|
||||
return [self createAndApplyPatchUsingVersion:LATEST_DELTA_DIFF_MAJOR_VERSION beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
XCTAssertEqual(SUBinaryDeltaMajorVersion3, LATEST_DELTA_DIFF_MAJOR_VERSION);
|
||||
|
||||
BOOL version3DeltaFormatWithLZMASuccess = [self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion3 compressionMode:SPUDeltaCompressionModeLZMA beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
|
||||
BOOL version3DeltaFormatWithBZIP2Success = [self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion3 compressionMode:SPUDeltaCompressionModeBzip2 beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
|
||||
BOOL version3DeltaFormatWithZLIBSuccess = [self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion3 compressionMode:SPUDeltaCompressionModeZLIB beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
|
||||
BOOL version2FormatSuccess = [self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion2 compressionMode:SPUDeltaCompressionModeDefault beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
|
||||
return (version3DeltaFormatWithLZMASuccess && version3DeltaFormatWithBZIP2Success && version3DeltaFormatWithZLIBSuccess && version2FormatSuccess);
|
||||
}
|
||||
|
||||
- (void)createAndApplyPatchWithHandler:(SUDeltaHandler)handler
|
||||
@@ -355,10 +365,10 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}];
|
||||
}
|
||||
|
||||
// Make sure old version patches still work for simple cases
|
||||
// Make sure old version patches are no longer supported
|
||||
- (void)testRegularFileAddedWithVersion1Delta
|
||||
{
|
||||
XCTAssertFalse([self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion1 beforeDiffHandler:nil afterDiffHandler:nil]);
|
||||
XCTAssertFalse([self createAndApplyPatchUsingVersion:SUBinaryDeltaMajorVersion1 compressionMode:SPUDeltaCompressionModeDefault beforeDiffHandler:nil afterDiffHandler:nil]);
|
||||
}
|
||||
|
||||
- (void)testDirectoryAdded
|
||||
@@ -423,12 +433,52 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}
|
||||
|
||||
- (void)testRegularFileMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R2"];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:sourceFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:destinationFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltes" length:6];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testLargerRegularFileMoveWithFileInPlace
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R2"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile3 = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/X"];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:sourceFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:destinationFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
NSData *data = [self bigData2];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile2 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile3 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularLargerFileMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
NSData *data = [self bigData2];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
@@ -436,6 +486,159 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileMoveWithPermissionChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R2"];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:sourceFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:destinationFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltes" length:6];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
if (chmod([destinationFile fileSystemRepresentation], 0777) != 0) {
|
||||
NSLog(@"Change Permission Error..");
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularLargerFileMoveWithPermissionChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [self bigData2];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
if (chmod([destinationFile fileSystemRepresentation], 0777) != 0) {
|
||||
NSLog(@"Change Permission Error..");
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSymbolicLinkMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R2"];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:sourceFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:destinationFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"C" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"C" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testLargerSymbolicLinkMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
NSString *destinationPath = @"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest";
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:destinationPath error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:destinationPath error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSymbolicLinkMoveWithPermissionChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R2"];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:sourceFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
[fileManager createDirectoryAtURL:[NSURL fileURLWithPath:destinationFile.stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"C" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"C" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (lchmod([destinationFile fileSystemRepresentation], 0777) != 0) {
|
||||
NSLog(@"Change Permission Error..");
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testLargerSymbolicLinkMoveWithPermissionChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
NSString *destinationPath = @"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest";
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:destinationPath error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:destinationPath error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
if (lchmod([destinationFile fileSystemRepresentation], 0777) != 0) {
|
||||
NSLog(@"Change Permission Error..");
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testCaseSensitiveRegularFileMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
@@ -607,7 +810,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testInvalidPermissionsInAfterTree
|
||||
- (void)testOddPermissionsInAfterTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
@@ -623,10 +826,9 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:nil];
|
||||
XCTAssertFalse(success);
|
||||
XCTAssertTrue(success);
|
||||
}
|
||||
|
||||
- (void)testBadPermissionsInBeforeTree
|
||||
@@ -778,6 +980,35 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testLargerRegularFileToSymlinkChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest" length:420];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:sourceFile2 atomically:YES]);
|
||||
|
||||
XCTAssertTrue([data writeToFile:destinationFile1 atomically:YES]);
|
||||
|
||||
NSString *destination = @"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest";
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile2 withDestinationPath:destination error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
// This would fail with version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSymlinkToRegularFileChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
@@ -787,7 +1018,7 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
NSData *data = [NSData dataWithBytes:"loltes" length:6];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
|
||||
@@ -804,13 +1035,40 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testLargerSymlinkToRegularFileChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest" length:420];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
|
||||
XCTAssertTrue([data writeToFile:destinationFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
NSString *destination = @"loltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltestloltest";
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile2 withDestinationPath:destination error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileToDirectoryChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
NSData *data = [NSData dataWithBytes:"loltes" length:6];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
@@ -27,7 +27,7 @@ class DeltaUpdate {
|
||||
class func create(from: ArchiveItem, to: ArchiveItem, archivePath: URL) throws -> DeltaUpdate {
|
||||
var applyDiffError: NSError?
|
||||
|
||||
if !createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, .version2, false, &applyDiffError) {
|
||||
if !createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, SUBinaryDeltaMajorVersionDefault, SPUDeltaCompressionModeDefault, DEFAULT_BZIP2_COMPRESSION_LEVEL, false, &applyDiffError) {
|
||||
throw applyDiffError!
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user