mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Added verbose option to BinaryDelta
Everything is now printed to stderr now, now that we have a verbose option. Printing to same stream avoids out-of-order messages
This commit is contained in:
1 parent
c7a8d5d42a
commit
fef73cc297
6 files changed
+146
-65
No files matched your search
Vendored
+1
-1
@@ -10,6 +10,6 @@
|
||||
#define SUBINARYDELTAAPPLY_H
|
||||
|
||||
@class NSString;
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile);
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose);
|
||||
|
||||
#endif
|
||||
Vendored
+18
-6
@@ -25,7 +25,7 @@ static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFil
|
||||
return success;
|
||||
}
|
||||
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile)
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose)
|
||||
{
|
||||
xar_t x = xar_open([patchFile fileSystemRepresentation], READ);
|
||||
if (!x) {
|
||||
@@ -99,7 +99,10 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Verifying source... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Verifying source...");
|
||||
}
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorDiffVersion);
|
||||
if (!beforeHash) {
|
||||
fprintf(stderr, "Unable to calculate hash of tree %s\n", [source fileSystemRepresentation]);
|
||||
@@ -111,7 +114,10 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nCopying files... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nCopying files...");
|
||||
}
|
||||
|
||||
if (!removeTree(destination)) {
|
||||
fprintf(stderr, "Failed to remove %s\n", [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
@@ -123,7 +129,9 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
|
||||
BOOL hasExtractKeyAvailable = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion);
|
||||
|
||||
fprintf(stdout, "\nPatching... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nPatching...");
|
||||
}
|
||||
xar_file_t file;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (file = xar_file_first(x, iter); file; file = xar_file_next(iter)) {
|
||||
@@ -164,7 +172,9 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
}
|
||||
xar_close(x);
|
||||
|
||||
fprintf(stdout, "\nVerifying destination... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nVerifying destination...");
|
||||
}
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorDiffVersion);
|
||||
if (!afterHash) {
|
||||
fprintf(stderr, "Unable to calculate hash of tree %s\n", [destination fileSystemRepresentation]);
|
||||
@@ -177,6 +187,8 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nDone!\n");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Vendored
+1
-1
@@ -12,6 +12,6 @@
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
|
||||
@class NSString;
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion);
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose);
|
||||
|
||||
#endif
|
||||
Vendored
+25
-14
@@ -184,15 +184,15 @@ static BOOL shouldChangePermissions(NSDictionary *originalInfo, NSDictionary *ne
|
||||
return YES;
|
||||
}
|
||||
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion)
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose)
|
||||
{
|
||||
if (majorVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "Version provided (%u) is not valid", majorVersion);
|
||||
fprintf(stderr, "Version provided (%u) is not valid\n", majorVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (majorVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "This program is too old to apply version %u", majorVersion);
|
||||
fprintf(stderr, "This program is too old to create a version %u patch, or the version number provided is invalid\n", majorVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,10 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Processing %s...", [source fileSystemRepresentation]);
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Processing %s...", [source fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
@@ -221,13 +224,13 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
if (!info) {
|
||||
fprintf(stderr, "Failed to retrieve info for file %s", ent->fts_path);
|
||||
fprintf(stderr, "Failed to retrieve info for file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
originalTreeState[key] = info;
|
||||
|
||||
if (aclExists(ent)) {
|
||||
fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in before-tree on file %s", ent->fts_path);
|
||||
fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in before-tree on file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +239,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorVersion);
|
||||
|
||||
if (!beforeHash) {
|
||||
fprintf(stderr, "Failed to generate hash for tree %s", [source fileSystemRepresentation]);
|
||||
fprintf(stderr, "Failed to generate hash for tree %s\n", [source fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -246,7 +249,10 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
newTreeState[key] = [NSNull null];
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nProcessing %s... ", [destination fileSystemRepresentation]);
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nProcessing %s...", [destination fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
sourcePaths[0] = [destination fileSystemRepresentation];
|
||||
fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
@@ -267,7 +273,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
if (!info) {
|
||||
fprintf(stderr, "Failed to retrieve info from file %s", ent->fts_path);
|
||||
fprintf(stderr, "Failed to retrieve info from file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -276,12 +282,12 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
|
||||
mode_t permissions = [info[INFO_PERMISSIONS_KEY] unsignedShortValue];
|
||||
if (!IS_VALID_PERMISSIONS(permissions)) {
|
||||
fprintf(stderr, "Invalid file permissions after-tree on file %s\nOnly permissions with modes 0755 and 0644 are supported", ent->fts_path);
|
||||
fprintf(stderr, "Invalid file permissions after-tree on file %s\nOnly permissions with modes 0755 and 0644 are supported\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (aclExists(ent)) {
|
||||
fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in after-tree on file %s", ent->fts_path);
|
||||
fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in after-tree on file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -309,11 +315,13 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorVersion);
|
||||
if (!afterHash) {
|
||||
fprintf(stderr, "Failed to generate hash for tree %s", [destination fileSystemRepresentation]);
|
||||
fprintf(stderr, "Failed to generate hash for tree %s\n", [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nGenerating delta... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nGenerating delta...");
|
||||
}
|
||||
|
||||
NSString *temporaryFile = temporaryPatchFile(patchFile);
|
||||
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
|
||||
@@ -416,7 +424,10 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
link([temporaryFile fileSystemRepresentation], [patchFile fileSystemRepresentation]);
|
||||
unlink([temporaryFile fileSystemRepresentation]);
|
||||
fprintf(stdout, "Done!\n");
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Done!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+100
-42
@@ -11,68 +11,126 @@
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#define VERBOSE_FLAG @"--verbose"
|
||||
#define VERSION_FLAG @"--version"
|
||||
|
||||
static void printUsage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, "BinaryDelta create [--version=<version>] <before-tree> <after-tree> <patch-file>\n");
|
||||
fprintf(stderr, "BinaryDelta apply <before-tree> <after-tree> <patch-file>\n");
|
||||
fprintf(stderr, "BinaryDelta create [--verbose --version=<version>] <before-tree> <after-tree> <patch-file>\n");
|
||||
fprintf(stderr, "BinaryDelta apply [--verbose] <before-tree> <after-tree> <patch-file>\n");
|
||||
}
|
||||
|
||||
static int runCreateCommand(NSArray *args)
|
||||
{
|
||||
if (args.count < 3 || args.count > 5) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 4 && ![args[0] isEqualToString:VERBOSE_FLAG] && ![args[0] hasPrefix:VERSION_FLAG]) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 5 && ![args[1] isEqualToString:VERBOSE_FLAG] && ![args[1] hasPrefix:VERSION_FLAG]) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL verbose =
|
||||
((args.count == 4 && [args[0] isEqualToString:VERBOSE_FLAG]) ||
|
||||
(args.count == 5 && [args[1] isEqualToString:VERBOSE_FLAG]));
|
||||
|
||||
NSString *versionField = nil;
|
||||
if (args.count == 4 && [args[0] hasPrefix:VERSION_FLAG]) {
|
||||
versionField = args[0];
|
||||
} else if (args.count == 5 && [args[1] hasPrefix:VERSION_FLAG]) {
|
||||
versionField = args[1];
|
||||
}
|
||||
|
||||
NSArray *versionComponents = nil;
|
||||
if (versionField) {
|
||||
versionComponents = [versionField componentsSeparatedByString:@"="];
|
||||
if (versionComponents.count != 2) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion patchVersion =
|
||||
!versionComponents ?
|
||||
LATEST_DELTA_DIFF_MAJOR_VERSION :
|
||||
(SUBinaryDeltaMajorVersion)[[versionComponents[1] componentsSeparatedByString:@"."][0] intValue]; // ignore minor version if provided
|
||||
|
||||
NSArray *fileArgs = [args subarrayWithRange:NSMakeRange(args.count - 3, 3)];
|
||||
|
||||
BOOL isDirectory;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) {
|
||||
fprintf(stderr, "Usage: before-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[1] isDirectory:&isDirectory] || !isDirectory) {
|
||||
fprintf(stderr, "Usage: after-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return createBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], patchVersion, verbose);
|
||||
}
|
||||
|
||||
static int runApplyCommand(NSArray *args)
|
||||
{
|
||||
if (args.count < 3 || args.count > 4) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 4 && ![args[0] isEqualToString:VERBOSE_FLAG]) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL verbose = (args.count == 4 && [args[0] isEqualToString:VERBOSE_FLAG]);
|
||||
|
||||
NSArray *fileArgs = [args subarrayWithRange:NSMakeRange(args.count - 3, 3)];
|
||||
|
||||
BOOL isDirectory;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) {
|
||||
fprintf(stderr, "Usage: before-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[2] isDirectory:&isDirectory] || isDirectory) {
|
||||
fprintf(stderr, "Usage: patch-file must be a file %d\n", isDirectory);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return applyBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], verbose);
|
||||
}
|
||||
|
||||
int main(int __unused argc, char __unused *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count < 5 || args.count > 6) {
|
||||
if (args.count < 3) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSString *command = args[1];
|
||||
NSArray *commandArguments = [args subarrayWithRange:NSMakeRange(2, args.count - 2)];
|
||||
|
||||
if (![command isEqualToString:@"create"] && args.count > 5) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion patchVersion;
|
||||
NSString *versionField = ([command isEqualToString:@"create"] && args.count == 6) ? args[2] : nil;
|
||||
if (!versionField) {
|
||||
patchVersion = LATEST_DELTA_DIFF_MAJOR_VERSION;
|
||||
} else {
|
||||
NSArray *versionComponents = [versionField componentsSeparatedByString:@"="];
|
||||
if (versionComponents.count != 2 || ![versionComponents[0] isEqualToString:@"--version"]) {
|
||||
printUsage();
|
||||
return 1;
|
||||
}
|
||||
// Ignore minor version if it's supplied
|
||||
patchVersion = (SUBinaryDeltaMajorVersion)[[versionComponents[1] componentsSeparatedByString:@"."][0] intValue];
|
||||
}
|
||||
|
||||
NSString *oldPath = args[args.count - 3];
|
||||
NSString *newPath = args[args.count - 2];
|
||||
NSString *patchFile = args[args.count - 1];
|
||||
|
||||
BOOL isDirectory;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:oldPath isDirectory:&isDirectory] || !isDirectory) {
|
||||
fprintf(stderr, "Usage: before-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result;
|
||||
if ([command isEqualToString:@"apply"]) {
|
||||
result = applyBinaryDelta(oldPath, newPath, patchFile);
|
||||
} else if ([command isEqualToString:@"create"]) {
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:newPath isDirectory:&isDirectory] || !isDirectory) {
|
||||
result = 1;
|
||||
fprintf(stderr, "Usage: after-tree must be a directory\n");
|
||||
} else {
|
||||
result = createBinaryDelta(oldPath, newPath, patchFile, patchVersion);
|
||||
}
|
||||
if ([command isEqualToString:@"create"]) {
|
||||
result = runCreateCommand(commandArguments);
|
||||
} else if ([command isEqualToString:@"apply"]) {
|
||||
result = runApplyCommand(commandArguments);
|
||||
} else {
|
||||
result = 1;
|
||||
printUsage();
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -26,7 +26,7 @@
|
||||
NSString *sourcePath = [[self.updateHost bundle] bundlePath];
|
||||
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath);
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO);
|
||||
if (!result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
|
||||
Reference in new issue
Block a user