diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-16 11:49:21 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-16 11:49:21 +0100 |
| commit | f8aa7d2a399ba7427e22c474191b1bd3331b647c (patch) | |
| tree | 464432a37e34f39c188aefef690466119288d86e /src/search.cpp | |
| parent | fe4cf7b218974a05af58851878ba65d5f0e1f348 (diff) | |
retrieve file size during dir iteration instead of after opening file
Diffstat (limited to 'src/search.cpp')
| -rw-r--r-- | src/search.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/search.cpp b/src/search.cpp index 5f95e8e..a455630 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -334,19 +334,21 @@ static void *_ts_search_thread(void *args) new_result->file_list_read_cursor++; ts_mutex_unlock(&new_result->files.mutex); - ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor); - ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8"); - if (content.file_error != FILE_ERROR_NONE) { - f->error = content.file_error; - } - if (content.content_length > megabytes(new_result->max_file_size)) { + + ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor); + if (f->file_size > megabytes(new_result->max_file_size)) { f->error = FILE_ERROR_TOO_BIG; } + else { + ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8"); + if (content.file_error != FILE_ERROR_NONE) { + f->error = content.file_error; + } - if (f->error == FILE_ERROR_NONE) _ts_search_file(f, content, new_result); - - free(content.content); + if (f->error == FILE_ERROR_NONE) _ts_search_file(f, content, new_result); + free(content.content); + } } finish_early: |
