mirror of
https://github.com/simon987/sist2.git
synced 2025-12-14 15:59:03 +00:00
use sqlite to save index, major thread pool refactor
This commit is contained in:
@@ -1,46 +1,12 @@
|
||||
#include "walk.h"
|
||||
#include "src/ctx.h"
|
||||
#include "src/parsing/parse.h"
|
||||
#include "src/parsing/fs_util.h"
|
||||
|
||||
#include <ftw.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define STR_STARTS_WITH(x, y) (strncmp(y, x, strlen(y) - 1) == 0)
|
||||
|
||||
__always_inline
|
||||
parse_job_t *create_fs_parse_job(const char *filepath, const struct stat *info, int base) {
|
||||
int len = (int) strlen(filepath);
|
||||
parse_job_t *job = malloc(sizeof(parse_job_t));
|
||||
|
||||
strcpy(job->filepath, filepath);
|
||||
job->base = base;
|
||||
char *p = strrchr(filepath + base, '.');
|
||||
if (p != NULL) {
|
||||
job->ext = (int) (p - filepath + 1);
|
||||
} else {
|
||||
job->ext = len;
|
||||
}
|
||||
|
||||
job->vfile.st_size = info->st_size;
|
||||
job->vfile.st_mode = info->st_mode;
|
||||
job->vfile.mtime = (int) info->st_mtim.tv_sec;
|
||||
|
||||
job->parent[0] = '\0';
|
||||
|
||||
memcpy(job->vfile.filepath, job->filepath, sizeof(job->vfile.filepath));
|
||||
job->vfile.read = fs_read;
|
||||
// Filesystem reads are always rewindable
|
||||
job->vfile.read_rewindable = fs_read;
|
||||
job->vfile.reset = fs_reset;
|
||||
job->vfile.close = fs_close;
|
||||
job->vfile.fd = -1;
|
||||
job->vfile.is_fs_file = TRUE;
|
||||
job->vfile.has_checksum = FALSE;
|
||||
job->vfile.rewind_buffer_size = 0;
|
||||
job->vfile.rewind_buffer = NULL;
|
||||
job->vfile.calculate_checksum = ScanCtx.calculate_checksums;
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
int sub_strings[30];
|
||||
#define EXCLUDED(str) (pcre_exec(ScanCtx.exclude, ScanCtx.exclude_extra, str, strlen(str), 0, 0, sub_strings, sizeof(sub_strings)) >= 0)
|
||||
@@ -55,7 +21,7 @@ int handle_entry(const char *filepath, const struct stat *info, int typeflag, st
|
||||
}
|
||||
|
||||
if (ScanCtx.exclude != NULL && EXCLUDED(filepath)) {
|
||||
LOG_DEBUGF("walk.c", "Excluded: %s", filepath)
|
||||
LOG_DEBUGF("walk.c", "Excluded: %s", filepath);
|
||||
|
||||
if (typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
||||
pthread_mutex_lock(&ScanCtx.dbg_file_counts_mu);
|
||||
@@ -69,13 +35,13 @@ int handle_entry(const char *filepath, const struct stat *info, int typeflag, st
|
||||
}
|
||||
|
||||
if (typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
||||
parse_job_t *job = create_fs_parse_job(filepath, info, ftw->base);
|
||||
parse_job_t *job = create_parse_job(filepath, (int) info->st_mtim.tv_sec, info->st_size);
|
||||
|
||||
tpool_work_arg_t arg = {
|
||||
.arg_size = sizeof(parse_job_t),
|
||||
.arg = job
|
||||
};
|
||||
tpool_add_work(ScanCtx.pool, parse, &arg);
|
||||
tpool_add_work(ScanCtx.pool, &(job_t) {
|
||||
.type = JOB_PARSE_JOB,
|
||||
.parse_job = job
|
||||
});
|
||||
free(job);
|
||||
}
|
||||
|
||||
return FTW_CONTINUE;
|
||||
@@ -116,7 +82,7 @@ int iterate_file_list(void *input_file) {
|
||||
}
|
||||
|
||||
if (ScanCtx.exclude != NULL && EXCLUDED(absolute_path)) {
|
||||
LOG_DEBUGF("walk.c", "Excluded: %s", absolute_path)
|
||||
LOG_DEBUGF("walk.c", "Excluded: %s", absolute_path);
|
||||
|
||||
if (S_ISREG(info.st_mode)) {
|
||||
pthread_mutex_lock(&ScanCtx.dbg_file_counts_mu);
|
||||
@@ -131,16 +97,14 @@ int iterate_file_list(void *input_file) {
|
||||
LOG_FATALF("walk.c", "File is not a children of root folder (%s): %s", ScanCtx.index.desc.root, buf);
|
||||
}
|
||||
|
||||
int base = (int) (strrchr(buf, '/') - buf) + 1;
|
||||
|
||||
parse_job_t *job = create_fs_parse_job(absolute_path, &info, base);
|
||||
parse_job_t *job = create_parse_job(absolute_path, (int) info.st_mtim.tv_sec, info.st_size);
|
||||
free(absolute_path);
|
||||
|
||||
tpool_work_arg_t arg = {
|
||||
.arg = job,
|
||||
.arg_size = sizeof(parse_job_t)
|
||||
};
|
||||
tpool_add_work(ScanCtx.pool, parse, &arg);
|
||||
tpool_add_work(ScanCtx.pool, &(job_t) {
|
||||
.type = JOB_PARSE_JOB,
|
||||
.parse_job = job
|
||||
});
|
||||
free(job);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user