summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-01-26 13:07:08 +0100
committerGravatar Nikias Bassen2019-01-26 13:07:08 +0100
commit67e3373d2e4bd55795e62b2d51ab99aeddf2406c (patch)
tree7376fb2296521a12a62ca4264717976761d7ead8
parent7e0eef5b4a6b43ee9534f6e6c60cddeefbf5c8a0 (diff)
downloadlibimobiledevice-67e3373d2e4bd55795e62b2d51ab99aeddf2406c.tar.gz
libimobiledevice-67e3373d2e4bd55795e62b2d51ab99aeddf2406c.tar.bz2
idevicebackup2: Move writing of RestoreApplications.plist to helper function, add command line switch to skip
-rw-r--r--tools/idevicebackup2.c129
1 files changed, 72 insertions, 57 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index e10846d..c9eb9cb 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -91,7 +91,8 @@ enum cmd_flags {
91 CMD_FLAG_ENCRYPTION_CHANGEPW = (1 << 8), 91 CMD_FLAG_ENCRYPTION_CHANGEPW = (1 << 8),
92 CMD_FLAG_FORCE_FULL_BACKUP = (1 << 9), 92 CMD_FLAG_FORCE_FULL_BACKUP = (1 << 9),
93 CMD_FLAG_CLOUD_ENABLE = (1 << 10), 93 CMD_FLAG_CLOUD_ENABLE = (1 << 10),
94 CMD_FLAG_CLOUD_DISABLE = (1 << 11) 94 CMD_FLAG_CLOUD_DISABLE = (1 << 11),
95 CMD_FLAG_RESTORE_SKIP_APPS = (1 << 12)
95}; 96};
96 97
97static int backup_domain_changed = 0; 98static int backup_domain_changed = 0;
@@ -536,6 +537,61 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t d
536 return ret; 537 return ret;
537} 538}
538 539
540static int write_restore_applications(plist_t info_plist, afc_client_t afc)
541{
542 int res = -1;
543 uint64_t restore_applications_file = 0;
544 char * applications_plist_xml = NULL;
545 uint32_t applications_plist_xml_length = 0;
546
547 plist_t applications_plist = plist_dict_get_item(info_plist, "Applications");
548 if (applications_plist) {
549 plist_to_xml(applications_plist, &applications_plist_xml, &applications_plist_xml_length);
550 }
551 if (!applications_plist_xml) {
552 printf("Error preparing RestoreApplications.plist\n");
553 goto leave;
554 }
555
556 afc_error_t afc_err = 0;
557 afc_err = afc_make_directory(afc, "/iTunesRestore");
558 if (afc_err != AFC_E_SUCCESS) {
559 printf("Error creating directory /iTunesRestore, error code %d\n", afc_err);
560 goto leave;
561 }
562
563 afc_err = afc_file_open(afc, "/iTunesRestore/RestoreApplications.plist", AFC_FOPEN_WR, &restore_applications_file);
564 if (afc_err != AFC_E_SUCCESS || !restore_applications_file) {
565 printf("Error creating /iTunesRestore/RestoreApplications.plist, error code %d\n", afc_err);
566 goto leave;
567 }
568
569 uint32_t bytes_written = 0;
570 afc_err = afc_file_write(afc, restore_applications_file, applications_plist_xml, applications_plist_xml_length, &bytes_written);
571 if (afc_err != AFC_E_SUCCESS || bytes_written != applications_plist_xml_length) {
572 printf("Error writing /iTunesRestore/RestoreApplications.plist, error code %d, wrote %u of %u bytes\n", afc_err, bytes_written, applications_plist_xml_length);
573 goto leave;
574 }
575
576 afc_err = afc_file_close(afc, restore_applications_file);
577 restore_applications_file = 0;
578 if (afc_err != AFC_E_SUCCESS) {
579 goto leave;
580 }
581 /* success */
582 res = 0;
583
584leave:
585 free(applications_plist_xml);
586
587 if (restore_applications_file) {
588 afc_file_close(afc, restore_applications_file);
589 restore_applications_file = 0;
590 }
591
592 return res;
593}
594
539static int mb2_status_check_snapshot_state(const char *path, const char *udid, const char *matches) 595static int mb2_status_check_snapshot_state(const char *path, const char *udid, const char *matches)
540{ 596{
541 int ret = 0; 597 int ret = 0;
@@ -1352,6 +1408,7 @@ static void print_usage(int argc, char **argv)
1352 printf(" --copy\t\tcreate a copy of backup folder before restoring.\n"); 1408 printf(" --copy\t\tcreate a copy of backup folder before restoring.\n");
1353 printf(" --settings\t\trestore device settings from the backup.\n"); 1409 printf(" --settings\t\trestore device settings from the backup.\n");
1354 printf(" --remove\t\tremove items which are not being restored\n"); 1410 printf(" --remove\t\tremove items which are not being restored\n");
1411 printf(" --skip-apps\t\tdo not trigger re-installation of apps after restore\n");
1355 printf(" --password PWD\tsupply the password of the source backup\n"); 1412 printf(" --password PWD\tsupply the password of the source backup\n");
1356 printf(" info\t\tshow details about last completed backup of device\n"); 1413 printf(" info\t\tshow details about last completed backup of device\n");
1357 printf(" list\t\tlist files of last completed backup in CSV format\n"); 1414 printf(" list\t\tlist files of last completed backup in CSV format\n");
@@ -1393,10 +1450,6 @@ int main(int argc, char *argv[])
1393 plist_t info_plist = NULL; 1450 plist_t info_plist = NULL;
1394 plist_t opts = NULL; 1451 plist_t opts = NULL;
1395 mobilebackup2_error_t err; 1452 mobilebackup2_error_t err;
1396 uint64_t restore_applications_file = 0;
1397 plist_t applications_plist = NULL;
1398 char * applications_plist_xml = NULL;
1399 uint32_t applications_plist_xml_length = 0;
1400 1453
1401 /* we need to exit cleanly on running backups and restores or we cause havok */ 1454 /* we need to exit cleanly on running backups and restores or we cause havok */
1402 signal(SIGINT, clean_exit); 1455 signal(SIGINT, clean_exit);
@@ -1459,6 +1512,9 @@ int main(int argc, char *argv[])
1459 else if (!strcmp(argv[i], "--remove")) { 1512 else if (!strcmp(argv[i], "--remove")) {
1460 cmd_flags |= CMD_FLAG_RESTORE_REMOVE_ITEMS; 1513 cmd_flags |= CMD_FLAG_RESTORE_REMOVE_ITEMS;
1461 } 1514 }
1515 else if (!strcmp(argv[i], "--skip-apps")) {
1516 cmd_flags |= CMD_FLAG_RESTORE_SKIP_APPS;
1517 }
1462 else if (!strcmp(argv[i], "--password")) { 1518 else if (!strcmp(argv[i], "--password")) {
1463 i++; 1519 i++;
1464 if (!argv[i]) { 1520 if (!argv[i]) {
@@ -1927,49 +1983,18 @@ checkpoint:
1927 } 1983 }
1928 PRINT_VERBOSE(1, "Backup password: %s\n", (backup_password == NULL ? "No":"Yes")); 1984 PRINT_VERBOSE(1, "Backup password: %s\n", (backup_password == NULL ? "No":"Yes"));
1929 1985
1930 /* Write /iTunesRestore/RestoreApplications.plist so that the device will start 1986 if (cmd_flags & CMD_FLAG_RESTORE_SKIP_APPS) {
1931 * restoring applications once the rest of the restore process is finished */ 1987 PRINT_VERBOSE(1, "Not writing RestoreApplications.plist - apps will not be re-installed after restore\n");
1932 applications_plist = plist_dict_get_item(info_plist, "Applications"); 1988 } else {
1933 if (applications_plist) { 1989 /* Write /iTunesRestore/RestoreApplications.plist so that the device will start
1934 plist_to_xml(applications_plist, &applications_plist_xml, &applications_plist_xml_length); 1990 * restoring applications once the rest of the restore process is finished */
1935 plist_free(applications_plist); 1991 if (write_restore_applications(info_plist, afc) < 0) {
1936 } 1992 cmd = CMD_LEAVE;
1937 if (!applications_plist_xml) { 1993 break;
1938 printf("Error preparing RestoreApplications.plist\n"); 1994 } else {
1939 cmd = CMD_LEAVE; 1995 PRINT_VERBOSE(1, "Wrote RestoreApplications.plist\n");
1940 break; 1996 }
1941 }
1942
1943 afc_error_t afc_err = 0;
1944 afc_err = afc_make_directory(afc, "/iTunesRestore");
1945 if (afc_err != AFC_E_SUCCESS) {
1946 printf("Error creating directory /iTunesRestore, error code %d\n", afc_err);
1947 cmd = CMD_LEAVE;
1948 break;
1949 }
1950
1951 afc_err = afc_file_open(afc, "/iTunesRestore/RestoreApplications.plist", AFC_FOPEN_WR, &restore_applications_file);
1952 if (afc_err != AFC_E_SUCCESS || !restore_applications_file) {
1953 printf("Error creating /iTunesRestore/RestoreApplications.plist, error code %d\n", afc_err);
1954 cmd = CMD_LEAVE;
1955 break;
1956 }
1957
1958 uint32_t bytes_written = 0;
1959 afc_err = afc_file_write(afc, restore_applications_file, applications_plist_xml, applications_plist_xml_length, &bytes_written);
1960 if (afc_err != AFC_E_SUCCESS || bytes_written != applications_plist_xml_length) {
1961 printf("Error writing /iTunesRestore/RestoreApplications.plist, error code %d, wrote %u of %u bytes\n", afc_err, bytes_written, applications_plist_xml_length);
1962 cmd = CMD_LEAVE;
1963 break;
1964 }
1965
1966 afc_err = afc_file_close(afc, restore_applications_file);
1967 restore_applications_file = 0;
1968 if (afc_err != AFC_E_SUCCESS) {
1969 cmd = CMD_LEAVE;
1970 break;
1971 } 1997 }
1972 printf("Wrote RestoreApplications.plist\n");
1973 1998
1974 /* Start restore */ 1999 /* Start restore */
1975 err = mobilebackup2_send_request(mobilebackup2, "Restore", udid, source_udid, opts); 2000 err = mobilebackup2_send_request(mobilebackup2, "Restore", udid, source_udid, opts);
@@ -2460,11 +2485,6 @@ files_out:
2460 mobilebackup2 = NULL; 2485 mobilebackup2 = NULL;
2461 } 2486 }
2462 2487
2463 if (restore_applications_file) {
2464 afc_file_close(afc, restore_applications_file);
2465 restore_applications_file = 0;
2466 }
2467
2468 if (afc) { 2488 if (afc) {
2469 afc_client_free(afc); 2489 afc_client_free(afc);
2470 afc = NULL; 2490 afc = NULL;
@@ -2475,11 +2495,6 @@ files_out:
2475 np = NULL; 2495 np = NULL;
2476 } 2496 }
2477 2497
2478 if (applications_plist_xml) {
2479 free(applications_plist_xml);
2480 applications_plist_xml = NULL;
2481 }
2482
2483 idevice_free(device); 2498 idevice_free(device);
2484 device = NULL; 2499 device = NULL;
2485 2500