/* do_search() * Description: Perform a lookup of the specified search string in all Clear manifests * for the current os release. */ void do_search(struct manifest *MoM, char search_type, char *search_term) { struct list *list; struct list *sublist; struct file *file; struct file *subfile; struct manifest *subman = NULL; int i, ret; bool done_with_bundle, done = false; bool hit = false; list = MoM->manifests; while (list && !done) { file = list->data; list = list->next; done_with_bundle = false; /* Load sub-manifest */ ret = load_manifests(file->last_change, file->last_change, file->filename, NULL, &subman); if (ret != 0) { printf("Failed to load manifest %s\n", file->filename); continue; } if (display_files) { /* Display bundle name. Marked up for pattern matchability */ printf("--Bundle: %s--\n", file->filename); } /* Loop through sub-manifest, searching for files matching the desired pattern */ sublist = subman->files; while (sublist && !done_with_bundle) { subfile = sublist->data; sublist = sublist->next; if (!subfile->is_file) { continue; } if (display_files) { /* Just display filename */ file_search(subfile->filename, NULL, NULL); } else if (search_type == 'e') { /* Search for exact match, not path addition */ if (file_search(subfile->filename, "", search_term)) { report_find(file->filename, subfile->filename); hit = true; if (!display_all) { done = true; } done_with_bundle = true; break; } } else if (search_type == 'l') { /* Check each supported library path for a match */ for (i = 0; lib_paths[i] != NULL; i++) { if (file_search(subfile->filename, lib_paths[i], search_term)) { report_find(file->filename, subfile->filename); hit = true; if (!display_all) { done = true; } done_with_bundle = true; break; } } } else if (search_type == 'b') { /* Check each supported path for binaries */ for (i = 0; bin_paths[i] != NULL; i++) { if (file_search(subfile->filename, bin_paths[i], search_term)) { report_find(file->filename, subfile->filename); hit = true; if (!display_all) { done = true; } done_with_bundle = true; break; } } } else { printf("Unrecognized search type. -b or -l supported\n"); done = true; break; } } free_manifest(subman); } if (!hit) { printf("Search term not found.\n"); } }
/* do_search() * Description: Perform a lookup of the specified search string in all Clear manifests * for the current os release. */ static void do_search(struct manifest *MoM, char search_type, char *search_term) { struct list *list; struct list *sublist; struct file *file; struct file *subfile; struct list *bundle_info = NULL; struct manifest *subman = NULL; int i; bool done_with_bundle, done_with_search = false; bool hit = false; bool man_load_failures = false; long hit_count = 0; list = MoM->manifests; while (list && !done_with_search) { file = list->data; list = list->next; done_with_bundle = false; /* Load sub-manifest */ subman = load_manifest(file->last_change, file, MoM, false); if (!subman) { fprintf(stderr, "Failed to load manifest %s\n", file->filename); man_load_failures = true; continue; } /* record contentsize and includes for install size calculation */ struct bundle_result *bundle = NULL; bundle = calloc(sizeof(struct bundle_result), 1); ON_NULL_ABORT(bundle); /* copy relevant information over for future use */ strncpy(bundle->bundle_name, subman->component, BUNDLE_NAME_MAXLEN - 1); bundle->topsize = subman->contentsize; /* do a deep copy of the includes list */ bundle->includes = list_deep_clone_strs(subman->includes); bundle_info = list_prepend_data(bundle_info, bundle); if (display_files) { /* Display bundle name. Marked up for pattern matchability */ fprintf(stderr, "--Bundle: %s--\n", file->filename); } /* Loop through sub-manifest, searching for files matching the desired pattern */ sublist = subman->files; while (sublist && !done_with_bundle) { subfile = sublist->data; sublist = sublist->next; if ((!subfile->is_file) && (!subfile->is_link)) { continue; } if (display_files) { /* Just display filename */ file_search(subfile->filename, NULL, NULL); } else if (search_type == '0') { /* Search for exact match, not path addition */ if (file_search(subfile->filename, "", search_term)) { report_find(file->filename, subfile->filename, search_term); hit = true; } } else if (search_type == 'l') { /* Check each supported library path for a match */ for (i = 0; lib_paths[i] != NULL; i++) { if (file_search(subfile->filename, lib_paths[i], search_term)) { report_find(file->filename, subfile->filename, search_term); hit = true; } } } else if (search_type == 'b') { /* Check each supported path for binaries */ for (i = 0; bin_paths[i] != NULL; i++) { if (file_search(subfile->filename, bin_paths[i], search_term)) { report_find(file->filename, subfile->filename, search_term); hit = true; } } } else { fprintf(stderr, "Unrecognized search type. -b or -l supported\n"); done_with_search = true; break; } /* Determine the level of completion we've reached */ if (hit) { if (scope == 'b') { done_with_bundle = true; } else if (scope == 'o') { done_with_bundle = true; done_with_search = true; } hit_count++; } hit = false; } free_manifest(subman); } if (!hit_count) { fprintf(stderr, "Search term not found.\n"); } bool display_size = (scope != 'o' && !man_load_failures); if (display_size) { apply_size_penalty(bundle_info); } list_free_list_and_data(bundle_info, free_bundle_result_data); if (num_results != INT_MAX) { sort_results(); } else { results = list_sort(results, bundle_size_cmp); } if (csv_format) { print_csv_results(); } else { print_final_results(display_size); } list_free_list_and_data(results, free_bundle_result_data); }