diff options
| author | 2024-10-25 23:11:47 +0200 | |
|---|---|---|
| committer | 2024-10-25 23:11:47 +0200 | |
| commit | 2726ee5cc0d4fa45dedf64972f1999431e152816 (patch) | |
| tree | c7108d71109bc27804fc9e38813260a93cf063f5 | |
| parent | 12c1c5ec567f6e4a7b107b52ef783ce54a254ce5 (diff) | |
| download | libimobiledevice-2726ee5cc0d4fa45dedf64972f1999431e152816.tar.gz libimobiledevice-2726ee5cc0d4fa45dedf64972f1999431e152816.tar.bz2 | |
idevicecrashreport: Allow removing crash logs without copying.
Can also be used with `-f` to only remove matching files.
| -rw-r--r-- | tools/idevicecrashreport.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c index 09bd537..e900fe8 100644 --- a/tools/idevicecrashreport.c +++ b/tools/idevicecrashreport.c | |||
| @@ -54,6 +54,7 @@ | |||
| 54 | const char* target_directory = NULL; | 54 | const char* target_directory = NULL; |
| 55 | static int extract_raw_crash_reports = 0; | 55 | static int extract_raw_crash_reports = 0; |
| 56 | static int keep_crash_reports = 0; | 56 | static int keep_crash_reports = 0; |
| 57 | static int remove_all = 0; | ||
| 57 | 58 | ||
| 58 | static int file_exists(const char* path) | 59 | static int file_exists(const char* path) |
| 59 | { | 60 | { |
| @@ -202,7 +203,7 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char | |||
| 202 | stbuf.st_nlink = atoi(fileinfo[i+1]); | 203 | stbuf.st_nlink = atoi(fileinfo[i+1]); |
| 203 | } else if (!strcmp(fileinfo[i], "st_mtime")) { | 204 | } else if (!strcmp(fileinfo[i], "st_mtime")) { |
| 204 | stbuf.st_mtime = (time_t)(atoll(fileinfo[i+1]) / 1000000000); | 205 | stbuf.st_mtime = (time_t)(atoll(fileinfo[i+1]) / 1000000000); |
| 205 | } else if (!strcmp(fileinfo[i], "LinkTarget")) { | 206 | } else if (!strcmp(fileinfo[i], "LinkTarget") && !remove_all) { |
| 206 | /* report latest crash report filename */ | 207 | /* report latest crash report filename */ |
| 207 | printf("Link: %s\n", (char*)target_filename + strlen(target_directory)); | 208 | printf("Link: %s\n", (char*)target_filename + strlen(target_directory)); |
| 208 | 209 | ||
| @@ -238,21 +239,29 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char | |||
| 238 | 239 | ||
| 239 | /* recurse into child directories */ | 240 | /* recurse into child directories */ |
| 240 | if (S_ISDIR(stbuf.st_mode)) { | 241 | if (S_ISDIR(stbuf.st_mode)) { |
| 242 | if (!remove_all) { | ||
| 241 | #ifdef WIN32 | 243 | #ifdef WIN32 |
| 242 | mkdir(target_filename); | 244 | mkdir(target_filename); |
| 243 | #else | 245 | #else |
| 244 | mkdir(target_filename, 0755); | 246 | mkdir(target_filename, 0755); |
| 245 | #endif | 247 | #endif |
| 248 | } | ||
| 246 | res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename, filename_filter); | 249 | res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename, filename_filter); |
| 247 | 250 | ||
| 248 | /* remove directory from device */ | 251 | /* remove directory from device */ |
| 249 | if (!keep_crash_reports) | 252 | if (!remove_all && !keep_crash_reports) |
| 250 | afc_remove_path(afc, source_filename); | 253 | afc_remove_path(afc, source_filename); |
| 251 | } else if (S_ISREG(stbuf.st_mode)) { | 254 | } else if (S_ISREG(stbuf.st_mode)) { |
| 252 | if (filename_filter != NULL && strstr(source_filename, filename_filter) == NULL) { | 255 | if (filename_filter != NULL && strstr(source_filename, filename_filter) == NULL) { |
| 253 | continue; | 256 | continue; |
| 254 | } | 257 | } |
| 255 | 258 | ||
| 259 | if (remove_all) { | ||
| 260 | printf("Remove: %s\n", source_filename); | ||
| 261 | afc_remove_path(afc, source_filename); | ||
| 262 | continue; | ||
| 263 | } | ||
| 264 | |||
| 256 | /* copy file to host */ | 265 | /* copy file to host */ |
| 257 | afc_error = afc_file_open(afc, source_filename, AFC_FOPEN_RDONLY, &handle); | 266 | afc_error = afc_file_open(afc, source_filename, AFC_FOPEN_RDONLY, &handle); |
| 258 | if(afc_error != AFC_E_SUCCESS) { | 267 | if(afc_error != AFC_E_SUCCESS) { |
| @@ -331,6 +340,7 @@ static void print_usage(int argc, char **argv, int is_error) | |||
| 331 | " -f, --filter NAME filter crash reports by NAME (case sensitive)\n" | 340 | " -f, --filter NAME filter crash reports by NAME (case sensitive)\n" |
| 332 | " -h, --help prints usage information\n" | 341 | " -h, --help prints usage information\n" |
| 333 | " -v, --version prints version information\n" | 342 | " -v, --version prints version information\n" |
| 343 | " --remove-all remove all crash logs found\n" | ||
| 334 | "\n" | 344 | "\n" |
| 335 | "Homepage: <" PACKAGE_URL ">\n" | 345 | "Homepage: <" PACKAGE_URL ">\n" |
| 336 | "Bug Reports: <" PACKAGE_BUGREPORT ">\n" | 346 | "Bug Reports: <" PACKAGE_BUGREPORT ">\n" |
| @@ -361,6 +371,7 @@ int main(int argc, char* argv[]) | |||
| 361 | { "filter", required_argument, NULL, 'f' }, | 371 | { "filter", required_argument, NULL, 'f' }, |
| 362 | { "extract", no_argument, NULL, 'e' }, | 372 | { "extract", no_argument, NULL, 'e' }, |
| 363 | { "keep", no_argument, NULL, 'k' }, | 373 | { "keep", no_argument, NULL, 'k' }, |
| 374 | { "remove-all", no_argument, NULL, 1 }, | ||
| 364 | { NULL, 0, NULL, 0} | 375 | { NULL, 0, NULL, 0} |
| 365 | }; | 376 | }; |
| 366 | 377 | ||
| @@ -405,6 +416,9 @@ int main(int argc, char* argv[]) | |||
| 405 | case 'k': | 416 | case 'k': |
| 406 | keep_crash_reports = 1; | 417 | keep_crash_reports = 1; |
| 407 | break; | 418 | break; |
| 419 | case 1: | ||
| 420 | remove_all = 1; | ||
| 421 | break; | ||
| 408 | default: | 422 | default: |
| 409 | print_usage(argc, argv, 1); | 423 | print_usage(argc, argv, 1); |
| 410 | return 2; | 424 | return 2; |
| @@ -414,12 +428,16 @@ int main(int argc, char* argv[]) | |||
| 414 | argv += optind; | 428 | argv += optind; |
| 415 | 429 | ||
| 416 | /* ensure a target directory was supplied */ | 430 | /* ensure a target directory was supplied */ |
| 417 | if (!argv[0]) { | 431 | if (!remove_all) { |
| 418 | fprintf(stderr, "ERROR: missing target directory.\n"); | 432 | if (!argv[0]) { |
| 419 | print_usage(argc+optind, argv-optind, 1); | 433 | fprintf(stderr, "ERROR: missing target directory.\n"); |
| 420 | return 2; | 434 | print_usage(argc+optind, argv-optind, 1); |
| 435 | return 2; | ||
| 436 | } | ||
| 437 | target_directory = argv[0]; | ||
| 438 | } else { | ||
| 439 | target_directory = "."; | ||
| 421 | } | 440 | } |
| 422 | target_directory = argv[0]; | ||
| 423 | 441 | ||
| 424 | /* check if target directory exists */ | 442 | /* check if target directory exists */ |
| 425 | if (!file_exists(target_directory)) { | 443 | if (!file_exists(target_directory)) { |
