From a2d8ca45084fb67ebef8c897ee23764770235da3 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 17 Aug 2010 04:11:10 +0200 Subject: idevicebackup: try multiple times to lock for sync otherwise, the sync in progress screen might keep showing up until you swipe to cancel on the device --- tools/idevicebackup.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'tools/idevicebackup.c') diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 76ae1a0..867eaad 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -38,6 +38,9 @@ #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" #define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" +#define LOCK_ATTEMPTS 50 +#define LOCK_WAIT 200000 + static mobilebackup_client_t mobilebackup = NULL; static lockdownd_client_t client = NULL; static idevice_t phone = NULL; @@ -873,12 +876,28 @@ int main(int argc, char *argv[]) afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); } if (lockfile) { + afc_error_t aerr; do_post_notification(NP_SYNC_LOCK_REQUEST); - if (afc_file_lock(afc, lockfile, AFC_LOCK_EX) == AFC_E_SUCCESS) { - do_post_notification(NP_SYNC_DID_START); - } else { + for (i = 0; i < LOCK_ATTEMPTS; i++) { + aerr = afc_file_lock(afc, lockfile, AFC_LOCK_EX); + if (aerr == AFC_E_SUCCESS) { + do_post_notification(NP_SYNC_DID_START); + break; + } else if (aerr == AFC_E_OP_WOULD_BLOCK) { + usleep(LOCK_WAIT); + continue; + } else { + fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr); + afc_file_close(afc, lockfile); + lockfile = 0; + cmd = CMD_LEAVE; + } + } + if (i == LOCK_ATTEMPTS) { + fprintf(stderr, "ERROR: timeout while locking for sync\n"); afc_file_close(afc, lockfile); lockfile = 0; + cmd = CMD_LEAVE; } } -- cgit v1.1-32-gdbae