diff options
author | Nikias Bassen | 2014-03-24 14:53:52 +0100 |
---|---|---|
committer | Nikias Bassen | 2014-03-24 14:53:52 +0100 |
commit | bca8d06db96c71199def7c0b50bd5a233ef57e38 (patch) | |
tree | f4e1cd181ed17d12fb2cc1cbf008d5ee6cd25970 | |
parent | 7113b03af0c99f7e22970955d09ad19a4af782b5 (diff) | |
download | libimobiledevice-bca8d06db96c71199def7c0b50bd5a233ef57e38.tar.gz libimobiledevice-bca8d06db96c71199def7c0b50bd5a233ef57e38.tar.bz2 |
idevicebackup: Do not read backup files entirely into memory during restore
-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: /* read data from file */ free(file_info_path); file_info_path = mobilebackup_build_path(backup_directory, hash, ".mddata"); - buffer_read_from_filename(file_info_path, &buffer, &length); + + /* determine file size */ +#ifdef WIN32 + struct _stati64 fst; + if (_stati64(file_info_path, &fst) != 0) +#else + struct stat fst; + if (stat(file_info_path, &fst) != 0) +#endif + { + printf("ERROR: stat() failed for '%s': %s\n", file_info_path, strerror(errno)); + free(file_info_path); + break; + } + length = fst.st_size; + + FILE *f = fopen(file_info_path, "rb"); + if (!f) { + printf("ERROR: could not open local file '%s': %s\n", file_info_path, strerror(errno)); + free(file_info_path); + break; + } free(file_info_path); /* send DLSendFile messages */ file_offset = 0; do { - if ((length-file_offset) <= 8192) + char buf[8192]; + size_t len = fread(buf, 1, sizeof(buf), f); + + if ((length-file_offset) <= sizeof(buf)) file_status = DEVICE_LINK_FILE_STATUS_LAST_HUNK; else file_status = DEVICE_LINK_FILE_STATUS_HUNK; @@ -1540,11 +1564,7 @@ files_out: plist_array_append_item(send_file_node, plist_new_string("DLSendFile")); - if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) - plist_array_append_item(send_file_node, plist_new_data(buffer+file_offset, length-file_offset)); - else - plist_array_append_item(send_file_node, plist_new_data(buffer+file_offset, 8192)); - + plist_array_append_item(send_file_node, plist_new_data(buf, len)); plist_array_append_item(send_file_node, plist_copy(file_info)); err = mobilebackup_send(mobilebackup, send_file_node); @@ -1562,7 +1582,7 @@ files_out: } } - file_offset += 8192; + file_offset += len; if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) printf("DONE\n"); |