diff options
| author | arf20 <aruizfernandez05@gmail.com> | 2025-12-08 00:31:59 +0100 |
|---|---|---|
| committer | arf20 <aruizfernandez05@gmail.com> | 2025-12-08 00:31:59 +0100 |
| commit | c2977c08c4778d0dff74ca92441bc33789687947 (patch) | |
| tree | d40430de2b8fa9a92c230fe98ddafcd8bd6eee59 | |
| parent | 0159795be5aa8423e8d223d057912e2d152efb4f (diff) | |
| download | arfnet2-search-c2977c08c4778d0dff74ca92441bc33789687947.tar.gz arfnet2-search-c2977c08c4778d0dff74ca92441bc33789687947.zip | |
periodic reindexing
| -rw-r--r-- | config.c | 28 | ||||
| -rw-r--r-- | config.h | 1 | ||||
| -rw-r--r-- | main.c | 31 | ||||
| -rw-r--r-- | search.cfg | 6 |
4 files changed, 48 insertions, 18 deletions
@@ -29,6 +29,7 @@ unsigned short port = 0; char *tmpl_path = NULL, *root = NULL, *subdir = NULL; +int magic_enable = 0, period = 86400; int config_load(const char *conf_path) @@ -63,19 +64,33 @@ config_load(const char *conf_path) fprintf(stderr, "[config] invalid port: %s\n", line); return -1; } - } else if (strcmp(line, "template") == 0) { + } + else if (strcmp(line, "template") == 0) { value[strlen(value) - 1] = '\0'; tmpl_path = strdup(value); printf("\ttemplate: %s\n", tmpl_path); - } else if (strcmp(line, "root") == 0) { + } + else if (strcmp(line, "root") == 0) { value[strlen(value) - 1] = '\0'; root = strdup(value); printf("\troot: %s\n", root); - } else if (strcmp(line, "subdir") == 0) { + } + else if (strcmp(line, "subdir") == 0) { value[strlen(value) - 1] = '\0'; subdir = strdup(value); printf("\tsubdir: %s\n", subdir); - } else { + } + else if (strcmp(line, "magic") == 0) { + value[strlen(value) - 1] = '\0'; + magic_enable = (strcmp(value, "true") == 0); + printf("\tmagic: %d\n", magic_enable); + } + else if (strcmp(line, "period") == 0) { + value[strlen(value) - 1] = '\0'; + period = atoi(value); + printf("\tperiod: %d\n", period); + } + else { fprintf(stderr, "[config] unknown key: %s\n", line); continue; } @@ -98,6 +113,11 @@ config_load(const char *conf_path) return -1; } + if (!subdir) { + fprintf(stderr, "[config] E: no link subdirectory given\n"); + return -1; + } + return 0; } @@ -32,6 +32,7 @@ /* config */ extern unsigned short port; extern char *tmpl_path, *root, *subdir; +extern int magic_enable, period; int config_load(const char *conf_path); @@ -347,27 +347,30 @@ int main() { return 1; } - /* begin indexing */ if (index_init() < 0) return 1; - time_t time_now = time(NULL); - struct tm *tm_now = gmtime(&time_now); - static char timestr[256]; - strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); + /* index loop */ + do { + time_t time_now = time(NULL); + struct tm *tm_now = gmtime(&time_now); + static char timestr[256]; + strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); - printf("[%s] [index] indexeding started...\n", timestr); + printf("[%s] [index] indexeding started...\n", timestr); - g_index = index_new(INIT_MAP_CAPACITY, root, 1); + if (g_index) + index_destroy(g_index); - time_now = time(NULL); - tm_now = gmtime(&time_now); - strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); + g_index = index_new(INIT_MAP_CAPACITY, root, magic_enable); - printf("[%s] [index] indexed finished\n", timestr); + time_now = time(NULL); + tm_now = gmtime(&time_now); + strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); - while (1) { - sleep(1000); - } + printf("[%s] [index] indexed finished\n", timestr); + + sleep(period); + } while (1); } @@ -9,6 +9,12 @@ template=index.htm.tmpl # root root=/home/arf20/projects/arfminesweeper +# read magic numbers (mime type) +magic=false + +# indexing period (seconds) +period=86400 + # http subdirectory for file links subdir=/files/ |
