summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-05-31 19:36:53 +0200
committerGravatar Nikias Bassen2010-05-31 19:36:53 +0200
commitb5b838a771c4b62023ee109d507fe83041001d27 (patch)
tree5fbe3b082932b105843d51dae6e2e2fe12cde6f4 /tools
parentc072273de30d458d7288df36f21770b2421a8408 (diff)
downloadlibimobiledevice-b5b838a771c4b62023ee109d507fe83041001d27.tar.gz
libimobiledevice-b5b838a771c4b62023ee109d507fe83041001d27.tar.bz2
idevicebackup: correctly handle removal of existing .mddata + .mdinfo files
This commit fixes the problem that the .mddata and .mdinfo files were not removed due to an incorrect check for the result of stat(). Since the file data is sent in chunks we have to check for existing files only when the first chunk of a file is received. That's why we now reset hunk_index each time a file has been completely received.
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicebackup.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index a8b37d9..1eb12b0 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -690,7 +690,7 @@ int main(int argc, char *argv[])
node_tmp = plist_array_get_item(message, 2);
/* first message hunk contains total backup size */
- if (hunk_index == 0) {
+ if ((hunk_index == 0) && (file_index == 0)) {
node = plist_dict_get_item(node_tmp, "BackupTotalSizeKey");
if (node) {
plist_get_uint_val(node, &backup_total_size);
@@ -747,7 +747,7 @@ int main(int argc, char *argv[])
filename_mdinfo = mobilebackup_build_path(backup_directory, file_path, ".mdinfo");
/* remove any existing file */
- if (stat(filename_mdinfo, &st) != 0)
+ if (stat(filename_mdinfo, &st) == 0)
remove(filename_mdinfo);
node = plist_dict_get_item(node_tmp, "BackupFileInfo");
@@ -768,7 +768,7 @@ int main(int argc, char *argv[])
filename_mddata = mobilebackup_build_path(backup_directory, file_path, is_manifest ? NULL: ".mddata");
/* if this is the first hunk, remove any existing file */
- if (stat(filename_mddata, &st) != 0)
+ if ((hunk_index == 0) && (stat(filename_mddata, &st) == 0))
remove(filename_mddata);
/* get file data hunk */
@@ -803,6 +803,8 @@ int main(int argc, char *argv[])
/* acknowlegdge that we received the file */
mobilebackup_send_backup_file_received(mobilebackup);
+ /* reset hunk_index */
+ hunk_index = 0;
}
if (quit_flag > 0) {