Create #defines for diff properties

This commit is contained in:
Zorg committed 2015-04-17 16:32:38 -04:00
1 parent fd68e649db
commit a715babce3
3 files changed
+47 -31

No files matched your search

+21 -21
View File
@@ -44,38 +44,38 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
xar_subdoc_t subdoc;
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
if (!strcmp(xar_subdoc_name(subdoc), "binary-delta-attributes")) {
if (!strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY)) {
const char *value = 0;
// available in version 2.0 or later
xar_subdoc_prop_get(subdoc, "major-version", &value);
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
if (value)
majorDiffVersion = (uint16_t)[@(value) intValue];
// available in version 2.0 or later
xar_subdoc_prop_get(subdoc, "minor-version", &value);
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
if (value)
minorDiffVersion = (uint16_t)[@(value) intValue];
// only available in version 1.0
xar_subdoc_prop_get(subdoc, "before-sha1", &value);
if (value)
expectedBeforeHashv1 = @(value);
// only available in version 1.0
xar_subdoc_prop_get(subdoc, "after-sha1", &value);
if (value)
expectedAfterHashv1 = @(value);
// available in version 2.0 or later
xar_subdoc_prop_get(subdoc, "before-tree-sha1", &value);
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value);
if (value)
expectedNewBeforeHash = @(value);
// available in version 2.0 or later
xar_subdoc_prop_get(subdoc, "after-tree-sha1", &value);
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_KEY, &value);
if (value)
expectedNewAfterHash = @(value);
// only available in version 1.0
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_OLD_KEY, &value);
if (value)
expectedBeforeHashv1 = @(value);
// only available in version 1.0
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_OLD_KEY, &value);
if (value)
expectedAfterHashv1 = @(value);
}
}
@@ -130,28 +130,28 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
NSString *destinationFilePath = [destination stringByAppendingPathComponent:path];
const char *value;
if (!xar_prop_get(file, "delete", &value) || !xar_prop_get(file, "delete-then-extract", &value)) {
if (!xar_prop_get(file, DELETE_KEY, &value) || !xar_prop_get(file, DELETE_THEN_EXTRACT_KEY, &value)) {
if (!removeTree(destinationFilePath)) {
fprintf(stderr, "delete or delete-then-extract: failed to remove %s\n", [destination fileSystemRepresentation]);
fprintf(stderr, "%s or %s: failed to remove %s\n", DELETE_KEY, DELETE_THEN_EXTRACT_KEY, [destination fileSystemRepresentation]);
return 1;
}
if (!xar_prop_get(file, "delete", &value))
if (!xar_prop_get(file, DELETE_KEY, &value))
continue;
}
if (!xar_prop_get(file, "binary-delta", &value)) {
if (!xar_prop_get(file, BINARY_DELTA_KEY, &value)) {
if (!applyBinaryDeltaToFile(x, file, sourceFilePath, destinationFilePath)) {
fprintf(stderr, "Unable to patch %s to destination %s\n", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation]);
return 1;
}
} else if (xar_prop_get(file, "mod-permissions", &value)) {
} else if (xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value)) {
if (xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]) != 0) {
fprintf(stderr, "Unable to extract file to %s\n", [destinationFilePath fileSystemRepresentation]);
return 1;
}
}
if (!xar_prop_get(file, "mod-permissions", &value)) {
if (!xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value)) {
if (!modifyPermissions(destinationFilePath, (mode_t)[[NSString stringWithUTF8String:value] intValue])) {
fprintf(stderr, "Unable to modify permissions (%s) on file %s\n", value, [destinationFilePath fileSystemRepresentation]);
return 1;
+14
View File
@@ -16,6 +16,20 @@
#define IS_VALID_PERMISSIONS(mode) \
(((mode & PERMISSION_FLAGS) == 0755) || ((mode & PERMISSION_FLAGS) == 0644))
#define BINARY_DELTA_ATTRIBUTES_KEY "binary-delta-attributes"
#define MAJOR_DIFF_VERSION_KEY "major-version"
#define MINOR_DIFF_VERSION_KEY "minor-version"
#define BEFORE_TREE_SHA1_KEY "before-tree-sha1"
#define AFTER_TREE_SHA1_KEY "after-tree-sha1"
#define DELETE_KEY "delete"
#define DELETE_THEN_EXTRACT_KEY "delete-then-extract"
#define BINARY_DELTA_KEY "binary-delta"
#define MODIFY_PERMISSIONS_KEY "mod-permissions"
// Properties no longer used in new patches
#define BEFORE_TREE_SHA1_OLD_KEY "before-sha1"
#define AFTER_TREE_SHA1_OLD_KEY "before-sha1"
#define MAJOR_VERSION_IS_AT_LEAST(actualMajor, expectedMajor) (actualMajor >= expectedMajor)
#define LATEST_MINOR_VERSION_FOR_MAJOR_VERSION(major) \
(major == AZURE_MAJOR_VERSION ? AZURE_MINOR_VERSION : BEIGE_MINOR_VERSION)
+12 -10
View File
@@ -319,14 +319,16 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
xar_subdoc_t attributes = xar_subdoc_new(x, "binary-delta-attributes");
xar_subdoc_t attributes = xar_subdoc_new(x, BINARY_DELTA_ATTRIBUTES_KEY);
xar_subdoc_prop_set(attributes, "major-version", [[NSString stringWithFormat:@"%u", majorVersion] UTF8String]);
xar_subdoc_prop_set(attributes, "minor-version", [[NSString stringWithFormat:@"%u", minorVersion] UTF8String]);
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]);
// Version 1 patches don't have a major or minor version field, so we need to differentiate between the hash keys
const char *beforeHashKey = MAJOR_VERSION_IS_AT_LEAST(majorVersion, BEIGE_MAJOR_VERSION) ? "before-tree-sha1" : "before-sha1";
const char *afterHashKey = MAJOR_VERSION_IS_AT_LEAST(majorVersion, BEIGE_MAJOR_VERSION) ? "after-tree-sha1" : "after-sha1";
const char *beforeHashKey =
MAJOR_VERSION_IS_AT_LEAST(majorVersion, BEIGE_MAJOR_VERSION) ? BEFORE_TREE_SHA1_KEY : BEFORE_TREE_SHA1_OLD_KEY;
const char *afterHashKey =
MAJOR_VERSION_IS_AT_LEAST(majorVersion, BEIGE_MAJOR_VERSION) ? AFTER_TREE_SHA1_KEY : AFTER_TREE_SHA1_OLD_KEY;
xar_subdoc_prop_set(attributes, beforeHashKey, [beforeHash UTF8String]);
xar_subdoc_prop_set(attributes, afterHashKey, [afterHash UTF8String]);
@@ -350,7 +352,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
if ([value isEqual:[NSNull null]]) {
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
assert(newFile);
xar_prop_set(newFile, "delete", "true");
xar_prop_set(newFile, DELETE_KEY, "true");
continue;
}
@@ -361,7 +363,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
if (shouldChangePermissions(originalInfo, newInfo)) {
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
assert(newFile);
xar_prop_set(newFile, "mod-permissions", [[NSString stringWithFormat:@"%u", [newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]] UTF8String]);
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [[NSString stringWithFormat:@"%u", [newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]] UTF8String]);
}
} else {
NSString *path = [destination stringByAppendingPathComponent:key];
@@ -369,7 +371,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
assert(newFile);
if (shouldDeleteThenExtract(originalInfo, newInfo)) {
xar_prop_set(newFile, "delete-then-extract", "true");
xar_prop_set(newFile, DELETE_THEN_EXTRACT_KEY, "true");
}
}
} else {
@@ -393,11 +395,11 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
}
xar_file_t newFile = xar_add_frompath(x, 0, [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
assert(newFile);
xar_prop_set(newFile, "binary-delta", "true");
xar_prop_set(newFile, BINARY_DELTA_KEY, "true");
unlink([resultPath fileSystemRepresentation]);
if (operation.permissions) {
xar_prop_set(newFile, "mod-permissions", [[NSString stringWithFormat:@"%u", [operation.permissions unsignedShortValue]] UTF8String]);
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [[NSString stringWithFormat:@"%u", [operation.permissions unsignedShortValue]] UTF8String]);
}
}