Skip to content

Commit 55b011d

Browse files
authored
Exit early from install/transfer callbacks if the dictionary contains an error. (#461)
1 parent c2c0f8d commit 55b011d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ void mount_developer_image(AMDeviceRef device) {
634634
}
635635

636636
mach_error_t transfer_callback(CFDictionaryRef dict, int arg) {
637+
if (CFDictionaryGetValue(dict, CFSTR("Error"))) {
638+
return 0;
639+
}
637640
int percent;
638641
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
639642
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
@@ -661,6 +664,9 @@ mach_error_t transfer_callback(CFDictionaryRef dict, int arg) {
661664
}
662665

663666
mach_error_t install_callback(CFDictionaryRef dict, int arg) {
667+
if (CFDictionaryGetValue(dict, CFSTR("Error"))) {
668+
return 0;
669+
}
664670
int percent;
665671
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
666672
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
@@ -681,21 +687,24 @@ mach_error_t install_callback(CFDictionaryRef dict, int arg) {
681687
// use this callback to determine which step is occuring and call the proper
682688
// callback.
683689
mach_error_t incremental_install_callback(CFDictionaryRef dict, int arg) {
684-
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
685-
if (CFEqual(status, CFSTR("TransferringPackage"))) {
686-
int percent;
687-
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
688-
int overall_percent = (percent / 2);
689-
NSLogOut(@"[%3d%%] %@", overall_percent, status);
690-
NSLogJSON(@{@"Event": @"TransferringPackage",
691-
@"OverallPercent": @(overall_percent),
692-
});
693-
return 0;
694-
} else if (CFEqual(status, CFSTR("CopyingFile"))) {
695-
return transfer_callback(dict, arg);
696-
} else {
697-
return install_callback(dict, arg);
698-
}
690+
if (CFDictionaryGetValue(dict, CFSTR("Error"))) {
691+
return 0;
692+
}
693+
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
694+
if (CFEqual(status, CFSTR("TransferringPackage"))) {
695+
int percent;
696+
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
697+
int overall_percent = (percent / 2);
698+
NSLogOut(@"[%3d%%] %@", overall_percent, status);
699+
NSLogJSON(@{@"Event": @"TransferringPackage",
700+
@"OverallPercent": @(overall_percent),
701+
});
702+
return 0;
703+
} else if (CFEqual(status, CFSTR("CopyingFile"))) {
704+
return transfer_callback(dict, arg);
705+
} else {
706+
return install_callback(dict, arg);
707+
}
699708
}
700709

701710
CFURLRef copy_device_app_url(AMDeviceRef device, CFStringRef identifier) {

0 commit comments

Comments
 (0)