diff options
| author | 2014-03-24 14:53:52 +0100 | |
|---|---|---|
| committer | 2014-03-24 14:53:52 +0100 | |
| commit | bca8d06db96c71199def7c0b50bd5a233ef57e38 (patch) | |
| tree | f4e1cd181ed17d12fb2cc1cbf008d5ee6cd25970 /tools | |
| parent | 7113b03af0c99f7e22970955d09ad19a4af782b5 (diff) | |
| download | libimobiledevice-bca8d06db96c71199def7c0b50bd5a233ef57e38.tar.gz libimobiledevice-bca8d06db96c71199def7c0b50bd5a233ef57e38.tar.bz2 | |
idevicebackup: Do not read backup files entirely into memory during restore
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/idevicebackup.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 0d7ba92..e30540e 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -1519,13 +1519,37 @@ files_out: | |||
| 1519 | /* read data from file */ | 1519 | /* read data from file */ |
| 1520 | free(file_info_path); | 1520 | free(file_info_path); |
| 1521 | file_info_path = mobilebackup_build_path(backup_directory, hash, ".mddata"); | 1521 | file_info_path = mobilebackup_build_path(backup_directory, hash, ".mddata"); |
| 1522 | buffer_read_from_filename(file_info_path, &buffer, &length); | 1522 | |
| 1523 | /* determine file size */ | ||
| 1524 | #ifdef WIN32 | ||
| 1525 | struct _stati64 fst; | ||
| 1526 | if (_stati64(file_info_path, &fst) != 0) | ||
| 1527 | #else | ||
| 1528 | struct stat fst; | ||
| 1529 | if (stat(file_info_path, &fst) != 0) | ||
| 1530 | #endif | ||
| 1531 | { | ||
| 1532 | printf("ERROR: stat() failed for '%s': %s\n", file_info_path, strerror(errno)); | ||
| 1533 | free(file_info_path); | ||
| 1534 | break; | ||
| 1535 | } | ||
| 1536 | length = fst.st_size; | ||
| 1537 | |||
| 1538 | FILE *f = fopen(file_info_path, "rb"); | ||
| 1539 | if (!f) { | ||
| 1540 | printf("ERROR: could not open local file '%s': %s\n", file_info_path, strerror(errno)); | ||
| 1541 | free(file_info_path); | ||
| 1542 | break; | ||
| 1543 | } | ||
| 1523 | free(file_info_path); | 1544 | free(file_info_path); |
| 1524 | 1545 | ||
| 1525 | /* send DLSendFile messages */ | 1546 | /* send DLSendFile messages */ |
| 1526 | file_offset = 0; | 1547 | file_offset = 0; |
| 1527 | do { | 1548 | do { |
| 1528 | if ((length-file_offset) <= 8192) | 1549 | char buf[8192]; |
| 1550 | size_t len = fread(buf, 1, sizeof(buf), f); | ||
| 1551 | |||
| 1552 | if ((length-file_offset) <= sizeof(buf)) | ||
| 1529 | file_status = DEVICE_LINK_FILE_STATUS_LAST_HUNK; | 1553 | file_status = DEVICE_LINK_FILE_STATUS_LAST_HUNK; |
| 1530 | else | 1554 | else |
| 1531 | file_status = DEVICE_LINK_FILE_STATUS_HUNK; | 1555 | file_status = DEVICE_LINK_FILE_STATUS_HUNK; |
| @@ -1540,11 +1564,7 @@ files_out: | |||
| 1540 | 1564 | ||
| 1541 | plist_array_append_item(send_file_node, plist_new_string("DLSendFile")); | 1565 | plist_array_append_item(send_file_node, plist_new_string("DLSendFile")); |
| 1542 | 1566 | ||
| 1543 | if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) | 1567 | plist_array_append_item(send_file_node, plist_new_data(buf, len)); |
| 1544 | plist_array_append_item(send_file_node, plist_new_data(buffer+file_offset, length-file_offset)); | ||
| 1545 | else | ||
| 1546 | plist_array_append_item(send_file_node, plist_new_data(buffer+file_offset, 8192)); | ||
| 1547 | |||
| 1548 | plist_array_append_item(send_file_node, plist_copy(file_info)); | 1568 | plist_array_append_item(send_file_node, plist_copy(file_info)); |
| 1549 | 1569 | ||
| 1550 | err = mobilebackup_send(mobilebackup, send_file_node); | 1570 | err = mobilebackup_send(mobilebackup, send_file_node); |
| @@ -1562,7 +1582,7 @@ files_out: | |||
| 1562 | } | 1582 | } |
| 1563 | } | 1583 | } |
| 1564 | 1584 | ||
| 1565 | file_offset += 8192; | 1585 | file_offset += len; |
| 1566 | 1586 | ||
| 1567 | if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) | 1587 | if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) |
| 1568 | printf("DONE\n"); | 1588 | printf("DONE\n"); |
