diff options
| author | 2025-06-29 23:54:16 +0200 | |
|---|---|---|
| committer | 2025-06-29 23:54:16 +0200 | |
| commit | cb34a171994562a78da7ea14b801759747d0fdf7 (patch) | |
| tree | 8a5c93443ec58b323e437db4655b603f622eeadb | |
| parent | 9049ffb7eaab5a75018bb8fb1a54a9c9903daf00 (diff) | |
| download | libimobiledevice-cb34a171994562a78da7ea14b801759747d0fdf7.tar.gz libimobiledevice-cb34a171994562a78da7ea14b801759747d0fdf7.tar.bz2 | |
tools: Use new afc_get_file_info_plist/afc_get_device_info_plist functions
| -rw-r--r-- | tools/afcclient.c | 171 | ||||
| -rw-r--r-- | tools/idevicebackup2.c | 14 | ||||
| -rw-r--r-- | tools/idevicecrashreport.c | 95 | ||||
| -rw-r--r-- | tools/ideviceimagemounter.c | 13 |
4 files changed, 121 insertions, 172 deletions
diff --git a/tools/afcclient.c b/tools/afcclient.c index 1cddb36..a958c23 100644 --- a/tools/afcclient.c +++ b/tools/afcclient.c | |||
| @@ -365,62 +365,55 @@ static char* get_realpath(const char* path) | |||
| 365 | 365 | ||
| 366 | static void handle_devinfo(afc_client_t afc, int argc, char** argv) | 366 | static void handle_devinfo(afc_client_t afc, int argc, char** argv) |
| 367 | { | 367 | { |
| 368 | char **info = NULL; | 368 | plist_t info = NULL; |
| 369 | afc_error_t err = afc_get_device_info(afc, &info); | 369 | afc_error_t err = afc_get_device_info_plist(afc, &info); |
| 370 | if (err == AFC_E_SUCCESS && info) { | 370 | if (err == AFC_E_SUCCESS && info) { |
| 371 | int i; | 371 | if (argc > 0 && !strcmp(argv[0], "--plain")) { |
| 372 | for (i = 0; info[i]; i += 2) { | 372 | plist_write_to_stream(info, stdout, PLIST_FORMAT_LIMD, PLIST_OPT_NONE); |
| 373 | printf("%s: %s\n", info[i], info[i+1]); | 373 | } else { |
| 374 | plist_write_to_stream(info, stdout, PLIST_FORMAT_JSON, PLIST_OPT_NONE); | ||
| 374 | } | 375 | } |
| 375 | } else { | 376 | } else { |
| 376 | printf("Error: Failed to get device info: %s (%d)\n", afc_strerror(err), err); | 377 | printf("Error: Failed to get device info: %s (%d)\n", afc_strerror(err), err); |
| 377 | } | 378 | } |
| 378 | afc_dictionary_free(info); | 379 | plist_free(info); |
| 379 | } | 380 | } |
| 380 | 381 | ||
| 381 | static int get_file_info_stat(afc_client_t afc, const char* path, struct afc_file_stat *stbuf) | 382 | static int get_file_info_stat(afc_client_t afc, const char* path, struct afc_file_stat *stbuf) |
| 382 | { | 383 | { |
| 383 | char **info = NULL; | 384 | plist_t info = NULL; |
| 384 | afc_error_t ret = afc_get_file_info(afc, path, &info); | 385 | afc_error_t ret = afc_get_file_info_plist(afc, path, &info); |
| 385 | memset(stbuf, 0, sizeof(struct afc_file_stat)); | 386 | memset(stbuf, 0, sizeof(struct afc_file_stat)); |
| 386 | if (ret != AFC_E_SUCCESS) { | 387 | if (ret != AFC_E_SUCCESS) { |
| 387 | return -1; | 388 | return -1; |
| 388 | } else if (!info) { | 389 | } else if (!info) { |
| 389 | return -1; | 390 | return -1; |
| 390 | } else { | ||
| 391 | // get file attributes from info list | ||
| 392 | int i; | ||
| 393 | for (i = 0; info[i]; i += 2) { | ||
| 394 | if (!strcmp(info[i], "st_size")) { | ||
| 395 | stbuf->st_size = atoll(info[i+1]); | ||
| 396 | } else if (!strcmp(info[i], "st_blocks")) { | ||
| 397 | stbuf->st_blocks = atoi(info[i+1]); | ||
| 398 | } else if (!strcmp(info[i], "st_ifmt")) { | ||
| 399 | if (!strcmp(info[i+1], "S_IFREG")) { | ||
| 400 | stbuf->st_mode = S_IFREG; | ||
| 401 | } else if (!strcmp(info[i+1], "S_IFDIR")) { | ||
| 402 | stbuf->st_mode = S_IFDIR; | ||
| 403 | } else if (!strcmp(info[i+1], "S_IFLNK")) { | ||
| 404 | stbuf->st_mode = S_IFLNK; | ||
| 405 | } else if (!strcmp(info[i+1], "S_IFBLK")) { | ||
| 406 | stbuf->st_mode = S_IFBLK; | ||
| 407 | } else if (!strcmp(info[i+1], "S_IFCHR")) { | ||
| 408 | stbuf->st_mode = S_IFCHR; | ||
| 409 | } else if (!strcmp(info[i+1], "S_IFIFO")) { | ||
| 410 | stbuf->st_mode = S_IFIFO; | ||
| 411 | } else if (!strcmp(info[i+1], "S_IFSOCK")) { | ||
| 412 | stbuf->st_mode = S_IFSOCK; | ||
| 413 | } | ||
| 414 | } else if (!strcmp(info[i], "st_nlink")) { | ||
| 415 | stbuf->st_nlink = atoi(info[i+1]); | ||
| 416 | } else if (!strcmp(info[i], "st_mtime")) { | ||
| 417 | stbuf->st_mtime = (time_t)(atoll(info[i+1]) / 1000000000); | ||
| 418 | } else if (!strcmp(info[i], "st_birthtime")) { /* available on iOS 7+ */ | ||
| 419 | stbuf->st_birthtime = (time_t)(atoll(info[i+1]) / 1000000000); | ||
| 420 | } | ||
| 421 | } | ||
| 422 | afc_dictionary_free(info); | ||
| 423 | } | 391 | } |
| 392 | stbuf->st_size = plist_dict_get_uint(info, "st_size"); | ||
| 393 | stbuf->st_blocks = plist_dict_get_uint(info, "st_blocks"); | ||
| 394 | const char* s_ifmt = plist_get_string_ptr(plist_dict_get_item(info, "st_ifmt"), NULL); | ||
| 395 | if (s_ifmt) { | ||
| 396 | if (!strcmp(s_ifmt, "S_IFREG")) { | ||
| 397 | stbuf->st_mode = S_IFREG; | ||
| 398 | } else if (!strcmp(s_ifmt, "S_IFDIR")) { | ||
| 399 | stbuf->st_mode = S_IFDIR; | ||
| 400 | } else if (!strcmp(s_ifmt, "S_IFLNK")) { | ||
| 401 | stbuf->st_mode = S_IFLNK; | ||
| 402 | } else if (!strcmp(s_ifmt, "S_IFBLK")) { | ||
| 403 | stbuf->st_mode = S_IFBLK; | ||
| 404 | } else if (!strcmp(s_ifmt, "S_IFCHR")) { | ||
| 405 | stbuf->st_mode = S_IFCHR; | ||
| 406 | } else if (!strcmp(s_ifmt, "S_IFIFO")) { | ||
| 407 | stbuf->st_mode = S_IFIFO; | ||
| 408 | } else if (!strcmp(s_ifmt, "S_IFSOCK")) { | ||
| 409 | stbuf->st_mode = S_IFSOCK; | ||
| 410 | } | ||
| 411 | } | ||
| 412 | stbuf->st_nlink = plist_dict_get_uint(info, "st_nlink"); | ||
| 413 | stbuf->st_mtime = (time_t)(plist_dict_get_uint(info, "st_mtime") / 1000000000); | ||
| 414 | /* available on iOS 7+ */ | ||
| 415 | stbuf->st_birthtime = (time_t)(plist_dict_get_uint(info, "st_birthtime") / 1000000000); | ||
| 416 | plist_free(info); | ||
| 424 | return 0; | 417 | return 0; |
| 425 | } | 418 | } |
| 426 | 419 | ||
| @@ -431,22 +424,23 @@ static void handle_file_info(afc_client_t afc, int argc, char** argv) | |||
| 431 | return; | 424 | return; |
| 432 | } | 425 | } |
| 433 | 426 | ||
| 434 | char **info = NULL; | 427 | plist_t info = NULL; |
| 435 | char* abspath = get_absolute_path(argv[0]); | 428 | char* abspath = get_absolute_path(argv[0]); |
| 436 | if (!abspath) { | 429 | if (!abspath) { |
| 437 | printf("Error: Invalid argument\n"); | 430 | printf("Error: Invalid argument\n"); |
| 438 | return; | 431 | return; |
| 439 | } | 432 | } |
| 440 | afc_error_t err = afc_get_file_info(afc, abspath, &info); | 433 | afc_error_t err = afc_get_file_info_plist(afc, abspath, &info); |
| 441 | if (err == AFC_E_SUCCESS && info) { | 434 | if (err == AFC_E_SUCCESS && info) { |
| 442 | int i; | 435 | if (argc > 1 && !strcmp(argv[1], "--plain")) { |
| 443 | for (i = 0; info[i]; i += 2) { | 436 | plist_write_to_stream(info, stdout, PLIST_FORMAT_LIMD, PLIST_OPT_NONE); |
| 444 | printf("%s: %s\n", info[i], info[i+1]); | 437 | } else { |
| 438 | plist_write_to_stream(info, stdout, PLIST_FORMAT_JSON, PLIST_OPT_NONE); | ||
| 445 | } | 439 | } |
| 446 | } else { | 440 | } else { |
| 447 | printf("Error: Failed to get file info for %s: %s (%d)\n", argv[0], afc_strerror(err), err); | 441 | printf("Error: Failed to get file info for %s: %s (%d)\n", argv[0], afc_strerror(err), err); |
| 448 | } | 442 | } |
| 449 | afc_dictionary_free(info); | 443 | plist_free(info); |
| 450 | free(abspath); | 444 | free(abspath); |
| 451 | } | 445 | } |
| 452 | 446 | ||
| @@ -784,28 +778,19 @@ static int __mkdir(const char* path) | |||
| 784 | 778 | ||
| 785 | static uint8_t get_file(afc_client_t afc, const char *srcpath, const char *dstpath, uint8_t force_overwrite, uint8_t recursive_get) | 779 | static uint8_t get_file(afc_client_t afc, const char *srcpath, const char *dstpath, uint8_t force_overwrite, uint8_t recursive_get) |
| 786 | { | 780 | { |
| 787 | char **info = NULL; | 781 | plist_t info = NULL; |
| 788 | uint64_t file_size = 0; | 782 | uint64_t file_size = 0; |
| 789 | afc_error_t err = afc_get_file_info(afc, srcpath, &info); | 783 | afc_error_t err = afc_get_file_info_plist(afc, srcpath, &info); |
| 790 | if (err == AFC_E_OBJECT_NOT_FOUND) { | 784 | if (err == AFC_E_OBJECT_NOT_FOUND) { |
| 791 | printf("Error: Failed to read from file '%s': %s (%d)\n", srcpath, afc_strerror(err), err); | 785 | printf("Error: Failed to read from file '%s': %s (%d)\n", srcpath, afc_strerror(err), err); |
| 792 | return 0; | 786 | return 0; |
| 793 | } | 787 | } |
| 794 | uint8_t is_dir = 0; | 788 | uint8_t is_dir = 0; |
| 795 | if (info) { | 789 | if (info) { |
| 796 | char **p = info; | 790 | file_size = plist_dict_get_uint(info, "st_size"); |
| 797 | while (p && *p) { | 791 | const char* ifmt = plist_get_string_ptr(plist_dict_get_item(info, "st_ifmt"), NULL); |
| 798 | if (!strcmp(*p, "st_size")) { | 792 | is_dir = (ifmt && !strcmp(ifmt, "S_IFDIR")); |
| 799 | p++; | 793 | plist_free(info); |
| 800 | file_size = (uint64_t) strtoull(*p, NULL, 10); | ||
| 801 | } | ||
| 802 | if (!strcmp(*p, "st_ifmt")) { | ||
| 803 | p++; | ||
| 804 | is_dir = !strcmp(*p, "S_IFDIR"); | ||
| 805 | } | ||
| 806 | p++; | ||
| 807 | } | ||
| 808 | afc_dictionary_free(info); | ||
| 809 | } | 794 | } |
| 810 | uint8_t succeed = 1; | 795 | uint8_t succeed = 1; |
| 811 | if (is_dir) { | 796 | if (is_dir) { |
| @@ -945,11 +930,11 @@ static void handle_get(afc_client_t afc, int argc, char **argv) | |||
| 945 | 930 | ||
| 946 | static uint8_t put_single_file(afc_client_t afc, const char *srcpath, const char *dstpath, uint8_t force_overwrite) | 931 | static uint8_t put_single_file(afc_client_t afc, const char *srcpath, const char *dstpath, uint8_t force_overwrite) |
| 947 | { | 932 | { |
| 948 | char **info = NULL; | 933 | plist_t info = NULL; |
| 949 | afc_error_t ret = afc_get_file_info(afc, dstpath, &info); | 934 | afc_error_t ret = afc_get_file_info_plist(afc, dstpath, &info); |
| 950 | // file exists, only overwrite with '-f' option was set | 935 | // file exists, only overwrite with '-f' option was set |
| 951 | if (ret == AFC_E_SUCCESS && info) { | 936 | if (ret == AFC_E_SUCCESS && info) { |
| 952 | afc_dictionary_free(info); | 937 | plist_free(info); |
| 953 | if (!force_overwrite) { | 938 | if (!force_overwrite) { |
| 954 | printf("Error: Failed to write into existing file without '-f' option: %s\n", dstpath); | 939 | printf("Error: Failed to write into existing file without '-f' option: %s\n", dstpath); |
| 955 | return 0; | 940 | return 0; |
| @@ -1030,10 +1015,11 @@ static uint8_t put_file(afc_client_t afc, const char *srcpath, const char *dstpa | |||
| 1030 | printf("Error: Failed to put directory without '-r' option: %s\n", srcpath); | 1015 | printf("Error: Failed to put directory without '-r' option: %s\n", srcpath); |
| 1031 | return 0; | 1016 | return 0; |
| 1032 | } | 1017 | } |
| 1033 | char **info = NULL; | 1018 | plist_t info = NULL; |
| 1034 | afc_error_t err = afc_get_file_info(afc, dstpath, &info); | 1019 | afc_error_t err = afc_get_file_info_plist(afc, dstpath, &info); |
| 1035 | //create if target directory does not exist | 1020 | //create if target directory does not exist |
| 1036 | afc_dictionary_free(info); | 1021 | plist_free(info); |
| 1022 | info = NULL; | ||
| 1037 | if (err == AFC_E_OBJECT_NOT_FOUND) { | 1023 | if (err == AFC_E_OBJECT_NOT_FOUND) { |
| 1038 | err = afc_make_directory(afc, dstpath); | 1024 | err = afc_make_directory(afc, dstpath); |
| 1039 | if (err != AFC_E_SUCCESS) { | 1025 | if (err != AFC_E_SUCCESS) { |
| @@ -1044,19 +1030,12 @@ static uint8_t put_file(afc_client_t afc, const char *srcpath, const char *dstpa | |||
| 1044 | printf("Error: Failed to put existing directory without '-f' option: %s\n", dstpath); | 1030 | printf("Error: Failed to put existing directory without '-f' option: %s\n", dstpath); |
| 1045 | return 0; | 1031 | return 0; |
| 1046 | } | 1032 | } |
| 1047 | afc_get_file_info(afc, dstpath, &info); | 1033 | afc_get_file_info_plist(afc, dstpath, &info); |
| 1048 | uint8_t is_dir = 0; | 1034 | uint8_t is_dir = 0; |
| 1049 | if (info) { | 1035 | if (info) { |
| 1050 | char **p = info; | 1036 | const char* ifmt = plist_get_string_ptr(plist_dict_get_item(info, "st_ifmt"), NULL); |
| 1051 | while (p && *p) { | 1037 | is_dir = (ifmt && !strcmp(ifmt, "S_IFDIR")); |
| 1052 | if (!strcmp(*p, "st_ifmt")) { | 1038 | plist_free(info); |
| 1053 | p++; | ||
| 1054 | is_dir = !strcmp(*p, "S_IFDIR"); | ||
| 1055 | break; | ||
| 1056 | } | ||
| 1057 | p++; | ||
| 1058 | } | ||
| 1059 | afc_dictionary_free(info); | ||
| 1060 | } | 1039 | } |
| 1061 | if (!is_dir) { | 1040 | if (!is_dir) { |
| 1062 | printf("Error: Failed to create or access directory: '%s'\n", dstpath); | 1041 | printf("Error: Failed to create or access directory: '%s'\n", dstpath); |
| @@ -1148,8 +1127,8 @@ static void handle_put(afc_client_t afc, int argc, char **argv) | |||
| 1148 | printf("Error: Invalid number of arguments\n"); | 1127 | printf("Error: Invalid number of arguments\n"); |
| 1149 | return; | 1128 | return; |
| 1150 | } | 1129 | } |
| 1151 | char **info = NULL; | 1130 | plist_t info = NULL; |
| 1152 | afc_error_t err = afc_get_file_info(afc, dstpath, &info); | 1131 | afc_error_t err = afc_get_file_info_plist(afc, dstpath, &info); |
| 1153 | // target does not exist, put directly | 1132 | // target does not exist, put directly |
| 1154 | if (err == AFC_E_OBJECT_NOT_FOUND) { | 1133 | if (err == AFC_E_OBJECT_NOT_FOUND) { |
| 1155 | put_file(afc, srcpath, dstpath, force_overwrite, recursive_put); | 1134 | put_file(afc, srcpath, dstpath, force_overwrite, recursive_put); |
| @@ -1158,16 +1137,9 @@ static void handle_put(afc_client_t afc, int argc, char **argv) | |||
| 1158 | } else { | 1137 | } else { |
| 1159 | uint8_t is_dir = 0; | 1138 | uint8_t is_dir = 0; |
| 1160 | if (info) { | 1139 | if (info) { |
| 1161 | char **p = info; | 1140 | const char* ifmt = plist_get_string_ptr(plist_dict_get_item(info, "st_ifmt"), NULL); |
| 1162 | while (p && *p) { | 1141 | is_dir = (ifmt && !strcmp(ifmt, "S_IFDIR")); |
| 1163 | if (!strcmp(*p, "st_ifmt")) { | 1142 | plist_free(info); |
| 1164 | p++; | ||
| 1165 | is_dir = !strcmp(*p, "S_IFDIR"); | ||
| 1166 | break; | ||
| 1167 | } | ||
| 1168 | p++; | ||
| 1169 | } | ||
| 1170 | afc_dictionary_free(info); | ||
| 1171 | } | 1143 | } |
| 1172 | // target is a directory, try to put under this directory | 1144 | // target is a directory, try to put under this directory |
| 1173 | if (is_dir) { | 1145 | if (is_dir) { |
| @@ -1228,19 +1200,12 @@ static void handle_cd(afc_client_t afc, int argc, char** argv) | |||
| 1228 | 1200 | ||
| 1229 | char* path = get_realpath(argv[0]); | 1201 | char* path = get_realpath(argv[0]); |
| 1230 | int is_dir = 0; | 1202 | int is_dir = 0; |
| 1231 | char **info = NULL; | 1203 | plist_t info = NULL; |
| 1232 | afc_error_t err = afc_get_file_info(afc, path, &info); | 1204 | afc_error_t err = afc_get_file_info_plist(afc, path, &info); |
| 1233 | if (err == AFC_E_SUCCESS && info) { | 1205 | if (err == AFC_E_SUCCESS && info) { |
| 1234 | int i; | 1206 | const char* ifmt = plist_get_string_ptr(plist_dict_get_item(info, "st_ifmt"), NULL); |
| 1235 | for (i = 0; info[i]; i += 2) { | 1207 | is_dir = (ifmt && !strcmp(ifmt, "S_IFDIR")); |
| 1236 | if (!strcmp(info[i], "st_ifmt")) { | 1208 | plist_free(info); |
| 1237 | if (!strcmp(info[i+1], "S_IFDIR")) { | ||
| 1238 | is_dir = 1; | ||
| 1239 | } | ||
| 1240 | break; | ||
| 1241 | } | ||
| 1242 | } | ||
| 1243 | afc_dictionary_free(info); | ||
| 1244 | } else { | 1209 | } else { |
| 1245 | printf("Error: Failed to get file info for %s: %s (%d)\n", path, afc_strerror(err), err); | 1210 | printf("Error: Failed to get file info for %s: %s (%d)\n", path, afc_strerror(err), err); |
| 1246 | free(path); | 1211 | free(path); |
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index cdce515..12d6083 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c | |||
| @@ -131,21 +131,15 @@ static void mobilebackup_afc_get_file_contents(afc_client_t afc, const char *fil | |||
| 131 | return; | 131 | return; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | char **fileinfo = NULL; | 134 | plist_t fileinfo = NULL; |
| 135 | uint32_t fsize = 0; | 135 | uint32_t fsize = 0; |
| 136 | 136 | ||
| 137 | afc_get_file_info(afc, filename, &fileinfo); | 137 | afc_get_file_info_plist(afc, filename, &fileinfo); |
| 138 | if (!fileinfo) { | 138 | if (!fileinfo) { |
| 139 | return; | 139 | return; |
| 140 | } | 140 | } |
| 141 | int i; | 141 | fsize = plist_dict_get_uint(fileinfo, "st_size"); |
| 142 | for (i = 0; fileinfo[i]; i+=2) { | 142 | plist_free(fileinfo); |
| 143 | if (!strcmp(fileinfo[i], "st_size")) { | ||
| 144 | fsize = atol(fileinfo[i+1]); | ||
| 145 | break; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | afc_dictionary_free(fileinfo); | ||
| 149 | 143 | ||
| 150 | if (fsize == 0) { | 144 | if (fsize == 0) { |
| 151 | return; | 145 | return; |
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c index ced5be2..b9869ae 100644 --- a/tools/idevicecrashreport.c +++ b/tools/idevicecrashreport.c | |||
| @@ -146,7 +146,7 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char | |||
| 146 | continue; | 146 | continue; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | char **fileinfo = NULL; | 149 | plist_t fileinfo = NULL; |
| 150 | struct stat stbuf; | 150 | struct stat stbuf; |
| 151 | memset(&stbuf, '\0', sizeof(struct stat)); | 151 | memset(&stbuf, '\0', sizeof(struct stat)); |
| 152 | 152 | ||
| @@ -173,70 +173,67 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char | |||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | /* get file information */ | 175 | /* get file information */ |
| 176 | afc_get_file_info(afc, source_filename, &fileinfo); | 176 | afc_get_file_info_plist(afc, source_filename, &fileinfo); |
| 177 | if (!fileinfo) { | 177 | if (!fileinfo) { |
| 178 | printf("Failed to read information for '%s'. Skipping...\n", source_filename); | 178 | printf("Failed to read information for '%s'. Skipping...\n", source_filename); |
| 179 | continue; | 179 | continue; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | /* parse file information */ | 182 | /* parse file information */ |
| 183 | int i; | 183 | stbuf.st_size = plist_dict_get_uint(fileinfo, "st_size"); |
| 184 | for (i = 0; fileinfo[i]; i+=2) { | 184 | const char* s_ifmt = plist_get_string_ptr(plist_dict_get_item(fileinfo, "st_ifmt"), NULL); |
| 185 | if (!strcmp(fileinfo[i], "st_size")) { | 185 | if (s_ifmt) { |
| 186 | stbuf.st_size = atoll(fileinfo[i+1]); | 186 | if (!strcmp(s_ifmt, "S_IFREG")) { |
| 187 | } else if (!strcmp(fileinfo[i], "st_ifmt")) { | 187 | stbuf.st_mode = S_IFREG; |
| 188 | if (!strcmp(fileinfo[i+1], "S_IFREG")) { | 188 | } else if (!strcmp(s_ifmt, "S_IFDIR")) { |
| 189 | stbuf.st_mode = S_IFREG; | 189 | stbuf.st_mode = S_IFDIR; |
| 190 | } else if (!strcmp(fileinfo[i+1], "S_IFDIR")) { | 190 | } else if (!strcmp(s_ifmt, "S_IFLNK")) { |
| 191 | stbuf.st_mode = S_IFDIR; | 191 | stbuf.st_mode = S_IFLNK; |
| 192 | } else if (!strcmp(fileinfo[i+1], "S_IFLNK")) { | 192 | } else if (!strcmp(s_ifmt, "S_IFBLK")) { |
| 193 | stbuf.st_mode = S_IFLNK; | 193 | stbuf.st_mode = S_IFBLK; |
| 194 | } else if (!strcmp(fileinfo[i+1], "S_IFBLK")) { | 194 | } else if (!strcmp(s_ifmt, "S_IFCHR")) { |
| 195 | stbuf.st_mode = S_IFBLK; | 195 | stbuf.st_mode = S_IFCHR; |
| 196 | } else if (!strcmp(fileinfo[i+1], "S_IFCHR")) { | 196 | } else if (!strcmp(s_ifmt, "S_IFIFO")) { |
| 197 | stbuf.st_mode = S_IFCHR; | 197 | stbuf.st_mode = S_IFIFO; |
| 198 | } else if (!strcmp(fileinfo[i+1], "S_IFIFO")) { | 198 | } else if (!strcmp(s_ifmt, "S_IFSOCK")) { |
| 199 | stbuf.st_mode = S_IFIFO; | 199 | stbuf.st_mode = S_IFSOCK; |
| 200 | } else if (!strcmp(fileinfo[i+1], "S_IFSOCK")) { | 200 | } |
| 201 | stbuf.st_mode = S_IFSOCK; | 201 | } |
| 202 | } | 202 | stbuf.st_nlink = plist_dict_get_uint(fileinfo, "st_nlink"); |
| 203 | } else if (!strcmp(fileinfo[i], "st_nlink")) { | 203 | stbuf.st_mtime = (time_t)(plist_dict_get_uint(fileinfo, "st_mtime") / 1000000000); |
| 204 | stbuf.st_nlink = atoi(fileinfo[i+1]); | 204 | const char* linktarget = plist_get_string_ptr(plist_dict_get_item(fileinfo, "LinkTarget"), NULL); |
| 205 | } else if (!strcmp(fileinfo[i], "st_mtime")) { | 205 | if (linktarget && !remove_all) { |
| 206 | stbuf.st_mtime = (time_t)(atoll(fileinfo[i+1]) / 1000000000); | 206 | /* report latest crash report filename */ |
| 207 | } else if (!strcmp(fileinfo[i], "LinkTarget") && !remove_all) { | 207 | printf("Link: %s\n", (char*)target_filename + strlen(target_directory)); |
| 208 | /* report latest crash report filename */ | 208 | |
| 209 | printf("Link: %s\n", (char*)target_filename + strlen(target_directory)); | 209 | /* remove any previous symlink */ |
| 210 | 210 | if (file_exists(target_filename)) { | |
| 211 | /* remove any previous symlink */ | 211 | remove(target_filename); |
| 212 | if (file_exists(target_filename)) { | 212 | } |
| 213 | remove(target_filename); | ||
| 214 | } | ||
| 215 | 213 | ||
| 216 | #ifndef _WIN32 | 214 | #ifndef _WIN32 |
| 217 | /* use relative filename */ | 215 | /* use relative filename */ |
| 218 | char* b = strrchr(fileinfo[i+1], '/'); | 216 | const char* b = strrchr(linktarget, '/'); |
| 219 | if (b == NULL) { | 217 | if (b == NULL) { |
| 220 | b = fileinfo[i+1]; | 218 | b = linktarget; |
| 221 | } else { | 219 | } else { |
| 222 | b++; | 220 | b++; |
| 223 | } | 221 | } |
| 224 | 222 | ||
| 225 | /* create a symlink pointing to latest log */ | 223 | /* create a symlink pointing to latest log */ |
| 226 | if (symlink(b, target_filename) < 0) { | 224 | if (symlink(b, target_filename) < 0) { |
| 227 | fprintf(stderr, "Can't create symlink to %s\n", b); | 225 | fprintf(stderr, "Can't create symlink to %s\n", b); |
| 228 | } | 226 | } |
| 229 | #endif | 227 | #endif |
| 230 | 228 | ||
| 231 | if (!keep_crash_reports) | 229 | if (!keep_crash_reports) |
| 232 | afc_remove_path(afc, source_filename); | 230 | afc_remove_path(afc, source_filename); |
| 233 | 231 | ||
| 234 | res = 0; | 232 | res = 0; |
| 235 | } | ||
| 236 | } | 233 | } |
| 237 | 234 | ||
| 238 | /* free file information */ | 235 | /* free file information */ |
| 239 | afc_dictionary_free(fileinfo); | 236 | plist_free(fileinfo); |
| 240 | 237 | ||
| 241 | /* recurse into child directories */ | 238 | /* recurse into child directories */ |
| 242 | if (S_ISDIR(stbuf.st_mode)) { | 239 | if (S_ISDIR(stbuf.st_mode)) { |
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c index 90c5190..b319d05 100644 --- a/tools/ideviceimagemounter.c +++ b/tools/ideviceimagemounter.c | |||
| @@ -598,20 +598,13 @@ int main(int argc, char **argv) | |||
| 598 | case DISK_IMAGE_UPLOAD_TYPE_AFC: | 598 | case DISK_IMAGE_UPLOAD_TYPE_AFC: |
| 599 | default: | 599 | default: |
| 600 | printf("Uploading %s --> afc:///%s\n", image_path, targetname); | 600 | printf("Uploading %s --> afc:///%s\n", image_path, targetname); |
| 601 | char **strs = NULL; | 601 | plist_t fileinfo = NULL; |
| 602 | if (afc_get_file_info(afc, PKG_PATH, &strs) != AFC_E_SUCCESS) { | 602 | if (afc_get_file_info_plist(afc, PKG_PATH, &fileinfo) != AFC_E_SUCCESS) { |
| 603 | if (afc_make_directory(afc, PKG_PATH) != AFC_E_SUCCESS) { | 603 | if (afc_make_directory(afc, PKG_PATH) != AFC_E_SUCCESS) { |
| 604 | fprintf(stderr, "WARNING: Could not create directory '%s' on device!\n", PKG_PATH); | 604 | fprintf(stderr, "WARNING: Could not create directory '%s' on device!\n", PKG_PATH); |
| 605 | } | 605 | } |
| 606 | } | 606 | } |
| 607 | if (strs) { | 607 | plist_free(fileinfo); |
| 608 | int i = 0; | ||
| 609 | while (strs[i]) { | ||
| 610 | free(strs[i]); | ||
| 611 | i++; | ||
| 612 | } | ||
| 613 | free(strs); | ||
| 614 | } | ||
| 615 | 608 | ||
| 616 | uint64_t af = 0; | 609 | uint64_t af = 0; |
| 617 | if ((afc_file_open(afc, targetname, AFC_FOPEN_WRONLY, &af) != | 610 | if ((afc_file_open(afc, targetname, AFC_FOPEN_WRONLY, &af) != |
