summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicebackup4.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/tools/idevicebackup4.c b/tools/idevicebackup4.c
index 55b7802..519b511 100644
--- a/tools/idevicebackup4.c
+++ b/tools/idevicebackup4.c
@@ -484,23 +484,31 @@ static int plist_strcmp(plist_t node, const char *str)
484 return ret; 484 return ret;
485} 485}
486 486
487/*static void mobilebackup_write_status(const char *path, int status) 487static int mobilebackup_status_check_snapshot_state(const char *path, const char *uuid, const char *matches)
488{ 488{
489 struct stat st; 489 int ret = -1;
490 plist_t status_plist = plist_new_dict(); 490 plist_t status_plist = NULL;
491 plist_dict_insert_item(status_plist, "Backup Success", plist_new_bool(status)); 491 gchar *file_path = g_build_path(G_DIR_SEPARATOR_S, path, uuid, "Status.plist", NULL);
492 gchar *file_path = mobilebackup_build_path(path, "Status", ".plist");
493
494 if (stat(file_path, &st) == 0)
495 remove(file_path);
496
497 plist_write_to_filename(status_plist, file_path, PLIST_FORMAT_XML);
498
499 plist_free(status_plist);
500 status_plist = NULL;
501 492
493 plist_read_from_filename(&status_plist, file_path);
502 g_free(file_path); 494 g_free(file_path);
503}*/ 495 if (!status_plist) {
496 printf("Could not read Status.plist!\n");
497 return ret;
498 }
499 plist_t node = plist_dict_get_item(status_plist, "SnapshotState");
500 if (node && (plist_get_node_type(node) == PLIST_STRING)) {
501 char* sval = NULL;
502 plist_get_string_val(node, &sval);
503 if (sval) {
504 ret = (strcmp(sval, matches) == 0) ? 1 : 0;
505 }
506 } else {
507 printf("%s: ERROR could not get SnapshotState key from Status.plist!\n", __func__);
508 }
509 plist_free(status_plist);
510 return ret;
511}
504 512
505static int mobilebackup_info_is_current_device(plist_t info) 513static int mobilebackup_info_is_current_device(plist_t info)
506{ 514{
@@ -1357,7 +1365,7 @@ int main(int argc, char *argv[])
1357 if (cmd == CMD_RESTORE) { 1365 if (cmd == CMD_RESTORE) {
1358 if (stat(info_path, &st) != 0) { 1366 if (stat(info_path, &st) != 0) {
1359 g_free(info_path); 1367 g_free(info_path);
1360 printf("ERROR: Backup directory \"%s\" is invalid. No Info.plist found.\n", backup_directory); 1368 printf("ERROR: Backup directory \"%s\" is invalid. No Info.plist found for UUID %s.\n", backup_directory, uuid);
1361 return -1; 1369 return -1;
1362 } 1370 }
1363 } 1371 }
@@ -1550,6 +1558,14 @@ checkpoint:
1550 break; 1558 break;
1551 case CMD_RESTORE: 1559 case CMD_RESTORE:
1552 /* TODO: verify battery on AC enough battery remaining */ 1560 /* TODO: verify battery on AC enough battery remaining */
1561
1562 /* verify if Status.plist says we read from an successful backup */
1563 if (!mobilebackup_status_check_snapshot_state(backup_directory, uuid, "finished")) {
1564 printf("ERROR: Cannot ensure we restore from a successful backup. Aborting.\n");
1565 cmd = CMD_LEAVE;
1566 break;
1567 }
1568
1553 printf("Starting Restore...\n"); 1569 printf("Starting Restore...\n");
1554 1570
1555 plist_t opts = plist_new_dict(); 1571 plist_t opts = plist_new_dict();
@@ -1938,7 +1954,6 @@ files_out:
1938 } 1954 }
1939 } while (1); 1955 } while (1);
1940 1956
1941 printf("Received %d files from device.\n", file_count);
1942#if 0 1957#if 0
1943 if (!quit_flag && !plist_strcmp(node, "DLMessageProcessMessage")) { 1958 if (!quit_flag && !plist_strcmp(node, "DLMessageProcessMessage")) {
1944 node_tmp = plist_array_get_item(message, 1); 1959 node_tmp = plist_array_get_item(message, 1);
@@ -1975,15 +1990,19 @@ files_out:
1975 } 1990 }
1976 } 1991 }
1977#endif 1992#endif
1978 if (backup_ok) { 1993 if (cmd == CMD_BACKUP) {
1979 // /* Status.plist (Info on how the backup process turned out) */ 1994 printf("Received %d files from device.\n", file_count);
1980 printf("Backup Successful.\n"); 1995 if (mobilebackup_status_check_snapshot_state(backup_directory, uuid, "finished")) {
1981 //mobilebackup_write_status(backup_directory, 1); 1996 printf("Backup Successful.\n");
1982 } else { 1997 } else {
1983 if (quit_flag) 1998 if (quit_flag)
1984 printf("Backup Aborted.\n"); 1999 printf("Backup Aborted.\n");
1985 else 2000 else
1986 printf("Backup Failed.\n"); 2001 printf("Backup Failed.\n");
2002 }
2003 } else if (cmd == CMD_RESTORE) {
2004 // TODO: check for success/failure
2005 printf("Restore operation finished. The device should reboot now to complete the process.\n");
1987 } 2006 }
1988 } 2007 }
1989 if (lockfile) { 2008 if (lockfile) {