Skip subtree of excluded directories

This commit is contained in:
simon987 2021-11-07 11:56:09 -05:00
parent 5b62fe77f2
commit be8eedc9c7
2 changed files with 17 additions and 5 deletions

View File

@ -43,26 +43,36 @@ int sub_strings[30];
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) { int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
if (typeflag == FTW_F && S_ISREG(info->st_mode) && ftw->level <= ScanCtx.depth) { if (ftw->level > ScanCtx.depth) {
if (typeflag == FTW_D) {
return FTW_SKIP_SUBTREE;
}
return FTW_CONTINUE;
}
if (ScanCtx.exclude != NULL && EXCLUDED(filepath)) { 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); pthread_mutex_lock(&ScanCtx.dbg_file_counts_mu);
ScanCtx.dbg_excluded_files_count += 1; ScanCtx.dbg_excluded_files_count += 1;
pthread_mutex_unlock(&ScanCtx.dbg_file_counts_mu); pthread_mutex_unlock(&ScanCtx.dbg_file_counts_mu);
return 0; return 0;
} else if (typeflag == FTW_D) {
return FTW_SKIP_SUBTREE;
}
} }
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_fs_parse_job(filepath, info, ftw->base);
tpool_add_work(ScanCtx.pool, parse, job); tpool_add_work(ScanCtx.pool, parse, job);
} }
return 0; return FTW_CONTINUE;
} }
#define MAX_FILE_DESCRIPTORS 64 #define MAX_FILE_DESCRIPTORS 64
int walk_directory_tree(const char *dirpath) { int walk_directory_tree(const char *dirpath) {
return nftw(dirpath, handle_entry, MAX_FILE_DESCRIPTORS, FTW_PHYS | FTW_DEPTH); return nftw(dirpath, handle_entry, MAX_FILE_DESCRIPTORS, FTW_PHYS | FTW_ACTIONRETVAL);
} }

View File

@ -1,6 +1,8 @@
#ifndef SIST_H #ifndef SIST_H
#define SIST_H #define SIST_H
#define _GNU_SOURCE
#ifndef FALSE #ifndef FALSE
#define FALSE (0) #define FALSE (0)
#define BOOL int #define BOOL int