summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-11-22 02:45:06 +0100
committerGravatar Nikias Bassen2012-11-22 02:45:06 +0100
commitc366b98bc7c7e414ba03471720af6acbdd399dcf (patch)
tree4b2d2e4b7586bdc1f6433da2506f21c3b77f303a
parenteef885a4d14b5fc63b7f0ef6e846b17c7228808c (diff)
downloadlibimobiledevice-c366b98bc7c7e414ba03471720af6acbdd399dcf.tar.gz
libimobiledevice-c366b98bc7c7e414ba03471720af6acbdd399dcf.tar.bz2
idevicebackup2: use RemoveDirectory/DeleteFile instead of remove() on win32
-rw-r--r--tools/idevicebackup2.c37
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)
624 } 624 }
625} 625}
626 626
627#ifdef WIN32
628static int win32err_to_errno(int err_value)
629{
630 switch (err_value) {
631 case ERROR_FILE_NOT_FOUND:
632 return ENOENT;
633 case ERROR_ALREADY_EXISTS:
634 return EEXIST;
635 default:
636 return EFAULT;
637 }
638}
639#endif
640
627static int mb2_handle_send_file(const char *backup_dir, const char *path, plist_t *errplist) 641static int mb2_handle_send_file(const char *backup_dir, const char *path, plist_t *errplist)
628{ 642{
629 uint32_t nlen = 0; 643 uint32_t nlen = 0;
@@ -1619,7 +1633,15 @@ checkpoint:
1619 free(str); 1633 free(str);
1620 char *oldpath = build_path(backup_directory, key, NULL); 1634 char *oldpath = build_path(backup_directory, key, NULL);
1621 1635
1636#ifdef WIN32
1637 struct stat st;
1638 if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode))
1639 RemoveDirectory(newpath);
1640 else
1641 DeleteFile(newpath);
1642#else
1622 remove(newpath); 1643 remove(newpath);
1644#endif
1623 if (rename(oldpath, newpath) < 0) { 1645 if (rename(oldpath, newpath) < 0) {
1624 printf("Renameing '%s' to '%s' failed: %s (%d)\n", oldpath, newpath, strerror(errno), errno); 1646 printf("Renameing '%s' to '%s' failed: %s (%d)\n", oldpath, newpath, strerror(errno), errno);
1625 errcode = errno_to_device_error(errno); 1647 errcode = errno_to_device_error(errno);
@@ -1658,11 +1680,26 @@ checkpoint:
1658 if (str) { 1680 if (str) {
1659 char *newpath = build_path(backup_directory, str, NULL); 1681 char *newpath = build_path(backup_directory, str, NULL);
1660 free(str); 1682 free(str);
1683#ifdef WIN32
1684 struct stat st;
1685 int res = 0;
1686 if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode))
1687 res = RemoveDirectory(newpath);
1688 else
1689 res = DeleteFile(newpath);
1690 if (!res) {
1691 int e = win32err_to_errno(GetLastError());
1692 printf("Could not remove '%s': %s (%d)\n", newpath, strerror(e), e);
1693 errcode = errno_to_device_error(e);
1694 errdesc = strerror(e);
1695 }
1696#else
1661 if (remove(newpath) < 0) { 1697 if (remove(newpath) < 0) {
1662 printf("Could not remove '%s': %s (%d)\n", newpath, strerror(errno), errno); 1698 printf("Could not remove '%s': %s (%d)\n", newpath, strerror(errno), errno);
1663 errcode = errno_to_device_error(errno); 1699 errcode = errno_to_device_error(errno);
1664 errdesc = strerror(errno); 1700 errdesc = strerror(errno);
1665 } 1701 }
1702#endif
1666 free(newpath); 1703 free(newpath);
1667 } 1704 }
1668 } 1705 }