diff options
author | Nikias Bassen | 2012-11-22 02:45:06 +0100 |
---|---|---|
committer | Nikias Bassen | 2012-11-22 02:45:06 +0100 |
commit | c366b98bc7c7e414ba03471720af6acbdd399dcf (patch) | |
tree | 4b2d2e4b7586bdc1f6433da2506f21c3b77f303a | |
parent | eef885a4d14b5fc63b7f0ef6e846b17c7228808c (diff) | |
download | libimobiledevice-c366b98bc7c7e414ba03471720af6acbdd399dcf.tar.gz libimobiledevice-c366b98bc7c7e414ba03471720af6acbdd399dcf.tar.bz2 |
idevicebackup2: use RemoveDirectory/DeleteFile instead of remove() on win32
-rw-r--r-- | tools/idevicebackup2.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index 2405c87..635a5ab 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -624,6 +624,20 @@ static int errno_to_device_error(int errno_value) } } +#ifdef WIN32 +static int win32err_to_errno(int err_value) +{ + switch (err_value) { + case ERROR_FILE_NOT_FOUND: + return ENOENT; + case ERROR_ALREADY_EXISTS: + return EEXIST; + default: + return EFAULT; + } +} +#endif + static int mb2_handle_send_file(const char *backup_dir, const char *path, plist_t *errplist) { uint32_t nlen = 0; @@ -1619,7 +1633,15 @@ checkpoint: free(str); char *oldpath = build_path(backup_directory, key, NULL); +#ifdef WIN32 + struct stat st; + if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode)) + RemoveDirectory(newpath); + else + DeleteFile(newpath); +#else remove(newpath); +#endif if (rename(oldpath, newpath) < 0) { printf("Renameing '%s' to '%s' failed: %s (%d)\n", oldpath, newpath, strerror(errno), errno); errcode = errno_to_device_error(errno); @@ -1658,11 +1680,26 @@ checkpoint: if (str) { char *newpath = build_path(backup_directory, str, NULL); free(str); +#ifdef WIN32 + struct stat st; + int res = 0; + if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode)) + res = RemoveDirectory(newpath); + else + res = DeleteFile(newpath); + if (!res) { + int e = win32err_to_errno(GetLastError()); + printf("Could not remove '%s': %s (%d)\n", newpath, strerror(e), e); + errcode = errno_to_device_error(e); + errdesc = strerror(e); + } +#else if (remove(newpath) < 0) { printf("Could not remove '%s': %s (%d)\n", newpath, strerror(errno), errno); errcode = errno_to_device_error(errno); errdesc = strerror(errno); } +#endif free(newpath); } } |