Skip to content

Commit

Permalink
Remove MAJOR_VERSION_IS_AT_LEAST()
Browse files Browse the repository at this point in the history
Not a terribly useful macro.
  • Loading branch information
zorgiepoo committed Sep 30, 2024
1 parent 30d21ff commit 0413bc7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Autoupdate/SPUSparkleDeltaArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ - (nullable SPUDeltaArchiveHeader *)readHeader
}

NSDate *bundleCreationDate;
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion4)) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
double bundleCreationTimeInterval = 0;
if (![self _readBuffer:&bundleCreationTimeInterval length:sizeof(bundleCreationTimeInterval)]) {
return nil;
Expand Down Expand Up @@ -868,7 +868,7 @@ - (void)writeHeader:(SPUDeltaArchiveHeader *)header
[self _writeBuffer:header.beforeTreeHash length:BINARY_DELTA_HASH_LENGTH];
[self _writeBuffer:header.afterTreeHash length:BINARY_DELTA_HASH_LENGTH];

if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion4)) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
NSDate *bundleCreationDate = header.bundleCreationDate;

// If bundleCreationDate == nil, we will write out a 0 time interval
Expand Down
2 changes: 0 additions & 2 deletions Autoupdate/SUBinaryDeltaCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#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)

// Relative path of custom icon data that may be set on a bundle via a resource fork
#define CUSTOM_ICON_PATH @"/Icon\r"

Expand Down
8 changes: 4 additions & 4 deletions Autoupdate/SUBinaryDeltaCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path,
}

NSData *fileHashKey;
if (majorVersion >= 4) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
if (ent->fts_info == FTS_D) {
fileHashKey = nil;
} else {
Expand Down Expand Up @@ -374,7 +374,7 @@ BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path,

const char *relativePathBytes = [relativePath fileSystemRepresentation];

if (majorVersion >= 4) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
crc32ChecksumValue = crc32(crc32ChecksumValue, (const void *)relativePathBytes, (uInt)strlen(relativePathBytes));
} else {
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
Expand All @@ -389,7 +389,7 @@ BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path,
// hardcoding a value helps avoid differences between filesystems.
uint16_t hashedPermissions = (ent->fts_info == FTS_SL) ? VALID_SYMBOLIC_LINK_PERMISSIONS : permissions;

if (majorVersion >= 4) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
crc32ChecksumValue = crc32(crc32ChecksumValue, (const void *)&type, sizeof(type));
crc32ChecksumValue = crc32(crc32ChecksumValue, (const void *)&hashedPermissions, sizeof(hashedPermissions));
} else {
Expand All @@ -402,7 +402,7 @@ BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path,

fts_close(fts);

if (majorVersion >= 4) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
uint64_t encodedCrc32ChecksumValue = crc32ChecksumValue;
memcpy(hashBuffer, &encodedCrc32ChecksumValue, sizeof(encodedCrc32ChecksumValue));
} else {
Expand Down
12 changes: 6 additions & 6 deletions Autoupdate/SUBinaryDeltaCreate.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
fts_close(fts);

// This dictionary will help us keep track of clones
NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *beforeHashToFileKeyDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;
NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *beforeHashToFileKeyDictionary = (majorVersion >= SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;

unsigned char beforeHash[BINARY_DELTA_HASH_LENGTH] = {0};
if (!getRawHashOfTreeAndFileTablesWithVersion(beforeHash, source, majorVersion, beforeHashToFileKeyDictionary, nil)) {
Expand Down Expand Up @@ -644,7 +644,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
// If we find any executable files that are using file system compression, that is sufficient
// for recording that the applier should re-apply file system compression.
// We check for executable files because they are likely candidates to be compressed.
if (!foundFilesystemCompression && MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) && ent->fts_info == FTS_F && (ent->fts_statp->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 && (ent->fts_statp->st_flags & UF_COMPRESSED) != 0) {
if (!foundFilesystemCompression && (majorVersion >= SUBinaryDeltaMajorVersion3) && ent->fts_info == FTS_F && (ent->fts_statp->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 && (ent->fts_statp->st_flags & UF_COMPRESSED) != 0) {
foundFilesystemCompression = true;

if (verbose) {
Expand Down Expand Up @@ -684,7 +684,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
fts_close(fts);

// This dictionary will help us keep track of clones
NSMutableDictionary<NSString *, NSData *> *afterFileKeyToHashDictionary = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;
NSMutableDictionary<NSString *, NSData *> *afterFileKeyToHashDictionary = (majorVersion >= SUBinaryDeltaMajorVersion3) ? [NSMutableDictionary dictionary] : nil;

unsigned char afterHash[BINARY_DELTA_HASH_LENGTH] = {0};
if (!getRawHashOfTreeAndFileTablesWithVersion(afterHash, destination, majorVersion, nil, afterFileKeyToHashDictionary)) {
Expand Down Expand Up @@ -725,7 +725,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF

// Record creation date of root bundle item
NSDate *bundleCreationDate;
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion4)) {
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
NSError *fileAttributesError = nil;
NSDictionary<NSFileAttributeKey, id> *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:destination error:&fileAttributesError];

Expand Down Expand Up @@ -769,7 +769,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
// Using a couple of heuristics we track if files have been moved to other locations within the app bundle
NSMutableDictionary<NSString *, NSString *> *frameworkVersionsSubstitutes = [NSMutableDictionary dictionary];
NSMutableDictionary<NSString *, NSString *> *fileSubstitutes = [NSMutableDictionary dictionary];
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3)) {
if (majorVersion >= SUBinaryDeltaMajorVersion3) {
// Heuristic #1: track if an old framework version was removed and a new framework version was added
// Keep track of these prefixes in a dictionary
// Eg: /Contents/Frameworks/Foo.framework/Versions/B/ (new) -> /Contents/Frameworks/Foo.framework/Versions/A/ (old)
Expand Down Expand Up @@ -887,7 +887,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
NSNumber *newPermissions = nil;
BOOL clonePermissionsChanged = NO;
BOOL clonedBinaryDiff = NO;
NSString *clonedRelativePath = MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBinaryDeltaMajorVersion3) ? cloneableRelativePath(afterFileKeyToHashDictionary, beforeHashToFileKeyDictionary, frameworkVersionsSubstitutes, fileSubstitutes, originalTreeState, newInfo, key, &newPermissions, &clonePermissionsChanged, &clonedBinaryDiff) : nil;
NSString *clonedRelativePath = (majorVersion >= SUBinaryDeltaMajorVersion3) ? cloneableRelativePath(afterFileKeyToHashDictionary, beforeHashToFileKeyDictionary, frameworkVersionsSubstitutes, fileSubstitutes, originalTreeState, newInfo, key, &newPermissions, &clonePermissionsChanged, &clonedBinaryDiff) : nil;
if (clonedRelativePath != nil) {
if (clonedBinaryDiff) {
NSDictionary *cloneInfo = originalTreeState[clonedRelativePath];
Expand Down

0 comments on commit 0413bc7

Please sign in to comment.