/** * Callback function to process a file found while recursively traversing * a directory. * * @param filepath path to the file * @param type file attributes * @param data the paramater specified, when calling find_file(). It shall be * non-zero for printing SFV header, zero for actual processing. */ static int find_file_callback(const char* filepath, int type, void* data) { int res = 0; if( !(type & FIND_IFDIR) ) { if(data) { if(!file_mask_match(opt.files_accept, filepath)) return 0; if(filepath[0] == '.' && IS_PATH_SEPARATOR(filepath[1])) filepath += 2; /* TODO: get size, fill file struct */ print_sfv_header_line(rhash_data.out, filepath, filepath); /* rhash_data.total_size += file.size */ } else { /* only check an update modes use crc_accept mask */ file_mask_array* masks = (opt.mode & (MODE_CHECK | MODE_UPDATE) ? opt.crc_accept : opt.files_accept); if(!file_mask_match(masks, filepath)) return 0; if(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) { res = check_hash_file(filepath, 1); } else { if(opt.mode & MODE_UPDATE) { res = update_hash_file(filepath); } else { /* default mode: calculate hash */ if(filepath[0] == '.' && IS_PATH_SEPARATOR(filepath[1])) filepath += 2; res = calculate_and_print_sums(rhash_data.out, filepath, filepath, NULL); rhash_data.processed++; } } } } if(res < 0) rhash_data.error_flag = 1; return 1; }
/** * Callback function to process files while recursively traversing a directory. * It hashes, checks or updates a file according to the current work mode. * * @param file the file to process * @param preprocess non-zero when preprocessing files, zero for actual processing. */ static int find_file_callback(file_t* file, int preprocess) { int res = 0; assert(!FILE_ISDIR(file)); assert(opt.search_data); if (rhash_data.interrupted) { opt.search_data->options |= FIND_CANCEL; return 0; } if (preprocess) { if (!file_mask_match(opt.files_accept, file->path) || must_skip_file(file)) { return 0; } if (opt.fmt & FMT_SFV) { print_sfv_header_line(rhash_data.out, file, 0); } rhash_data.batch_size += file->size; } else { int not_root = !(file->mode & FILE_IFROOT); if (not_root) { /* only check and update modes use the crc_accept mask */ file_mask_array* masks = (opt.mode & (MODE_CHECK | MODE_UPDATE) ? opt.crc_accept : opt.files_accept); if (!file_mask_match(masks, file->path)) return 0; } if (must_skip_file(file)) return 0; if (opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) { res = check_hash_file(file, not_root); } else { if (opt.mode & MODE_UPDATE) { res = update_hash_file(file); } else { /* default mode: calculate hash */ const char* print_path = file->path; if (print_path[0] == '.' && IS_PATH_SEPARATOR(print_path[1])) print_path += 2; res = calculate_and_print_sums(rhash_data.out, file, print_path); if (rhash_data.interrupted) return 0; rhash_data.processed++; } } } if (res < 0) rhash_data.error_flag = 1; return 1; }