diff options
author | Nikias Bassen | 2010-08-17 04:11:10 +0200 |
---|---|---|
committer | Nikias Bassen | 2010-08-17 04:11:10 +0200 |
commit | a2d8ca45084fb67ebef8c897ee23764770235da3 (patch) | |
tree | 3c31a8d4bc63abff59b16c31f255b577ade38add | |
parent | 34ebb8accc32a161bd6a7cebf9d8c909696d0634 (diff) | |
download | libimobiledevice-a2d8ca45084fb67ebef8c897ee23764770235da3.tar.gz libimobiledevice-a2d8ca45084fb67ebef8c897ee23764770235da3.tar.bz2 |
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
-rw-r--r-- | tools/idevicebackup.c | 25 |
1 files changed, 22 insertions, 3 deletions
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; } } |