Fix for #3 and maximum scan depth

This commit is contained in:
simon 2019-11-19 11:23:30 -05:00
parent 893ff145c5
commit 373ac01e4e
10 changed files with 33 additions and 9 deletions

View File

@ -1,3 +1,4 @@
rm ./sist2
cp ../sist2 . cp ../sist2 .
version=$(./sist2 --version) version=$(./sist2 --version)

View File

@ -14,6 +14,9 @@
scan_args_t *scan_args_create() { scan_args_t *scan_args_create() {
scan_args_t *args = calloc(sizeof(scan_args_t), 1); scan_args_t *args = calloc(sizeof(scan_args_t), 1);
args->depth = -1;
return args; return args;
} }
@ -80,6 +83,12 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
return 1; return 1;
} }
if (args->depth < 0) {
args->depth = G_MAXINT32;
} else {
args->depth += 1;
}
if (args->name == NULL) { if (args->name == NULL) {
args->name = g_path_get_basename(args->output); args->name = g_path_get_basename(args->output);
} }

View File

@ -12,6 +12,7 @@ typedef struct scan_args {
char *output; char *output;
char *rewrite_url; char *rewrite_url;
char *name; char *name;
int depth;
char *path; char *path;
} scan_args_t; } scan_args_t;

View File

@ -15,6 +15,7 @@ struct {
int threads; int threads;
int content_size; int content_size;
float tn_qscale; float tn_qscale;
int depth;
size_t stat_tn_size; size_t stat_tn_size;
size_t stat_index_size; size_t stat_index_size;

View File

@ -20,7 +20,7 @@ parse_job_t *create_parse_job(const char *filepath, const struct stat *info, int
} }
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)) { if (ftw->level <= ScanCtx.depth && typeflag == FTW_F && S_ISREG(info->st_mode)) {
parse_job_t *job = create_parse_job(filepath, info, ftw->base); parse_job_t *job = create_parse_job(filepath, info, ftw->base);
tpool_add_work(ScanCtx.pool, parse, job); tpool_add_work(ScanCtx.pool, parse, job);
} }

View File

@ -10,7 +10,7 @@
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0" #define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
static const char *const Version = "1.1.7"; static const char *const Version = "1.1.8";
static const char *const usage[] = { static const char *const usage[] = {
"sist2 scan [OPTION]... PATH", "sist2 scan [OPTION]... PATH",
"sist2 index [OPTION]... INDEX", "sist2 index [OPTION]... INDEX",
@ -53,6 +53,7 @@ void sist2_scan(scan_args_t *args) {
ScanCtx.tn_size = args->size; ScanCtx.tn_size = args->size;
ScanCtx.content_size = args->content_size; ScanCtx.content_size = args->content_size;
ScanCtx.threads = args->threads; ScanCtx.threads = args->threads;
ScanCtx.depth = args->depth;
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path)); strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name)); strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root)); strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
@ -231,6 +232,8 @@ int main(int argc, const char *argv[]) {
OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"), OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"),
OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."), OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."),
OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"), OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"),
OPT_INTEGER(0, "depth", &scan_args->depth, "Scan up to DEPTH subdirectories deep. "
"Use 0 to only scan files in PATH. DEFAULT: -1"),
#ifndef SIST_SCAN_ONLY #ifndef SIST_SCAN_ONLY
OPT_GROUP("Index options"), OPT_GROUP("Index options"),

View File

@ -114,12 +114,18 @@ static void *tpool_worker(void *arg) {
pthread_mutex_unlock(&(pool->work_mutex)); pthread_mutex_unlock(&(pool->work_mutex));
if (work != NULL) { if (work != NULL) {
if (pool->stop) {
break;
}
work->func(work->arg); work->func(work->arg);
free(work); free(work);
} }
pthread_mutex_lock(&(pool->work_mutex)); pthread_mutex_lock(&(pool->work_mutex));
if (work != NULL) {
pool->done_cnt++; pool->done_cnt++;
}
progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size); progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
@ -142,11 +148,14 @@ void tpool_wait(tpool_t *pool) {
if (pool->done_cnt < pool->work_cnt) { if (pool->done_cnt < pool->work_cnt) {
pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex)); pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex));
} else { } else {
usleep(500000);
if (pool->done_cnt == pool->work_cnt) {
pool->stop = 1; pool->stop = 1;
break; break;
} }
progress_bar_print(100.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
} }
}
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
pthread_mutex_unlock(&(pool->work_mutex)); pthread_mutex_unlock(&(pool->work_mutex));
} }

View File

@ -1,4 +1,4 @@
#import "auth_basic.h" #include "auth_basic.h"
#define UNAUTHORIZED_TEXT "Unauthorized" #define UNAUTHORIZED_TEXT "Unauthorized"

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@
<nav class="navbar navbar-expand-lg"> <nav class="navbar navbar-expand-lg">
<a class="navbar-brand" href="/">sist2</a> <a class="navbar-brand" href="/">sist2</a>
<span class="badge badge-pill version">v1.1.7</span> <span class="badge badge-pill version">v1.1.8</span>
<span class="tagline">Lightning-fast file system indexer and search tool </span> <span class="tagline">Lightning-fast file system indexer and search tool </span>
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a> <a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
</nav> </nav>