diff --git a/Makefile b/Makefile index ce40698..1cb031a 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ install : $(PROGRAMS) cp $^ $(HOME)/bin/ dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \ - proc-cache.o error.o + proc-cache.o dlhist.o error.o dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o error.o dlight-read-config : read-config.o buffer.o env.o cconf.o error.o dlight-filter-check: filter-check.o filter.o error.o diff --git a/dlhist.c b/dlhist.c index 5c5f2c8..e93520d 100644 --- a/dlhist.c +++ b/dlhist.c @@ -68,7 +68,7 @@ static unsigned hash(const char *s) { unsigned h; - for(h = 0; *s; s++) + for(h = 0; *s; s++) h = ((unsigned)*s) + (h << 6) + (h << 16) - h; return h; } @@ -297,7 +297,7 @@ static int path_cmp(const char *a, const char *b) { if (stat(a, &sa) < 0 || stat(b, &sb) < 0) return 0; - return sa.st_dev == sb.st_dev && + return sa.st_dev == sb.st_dev && sa.st_ino == sb.st_ino; } diff --git a/dlight.c b/dlight.c index 31c373e..73885f7 100644 --- a/dlight.c +++ b/dlight.c @@ -9,12 +9,14 @@ #include "env.h" #include "error.h" #include "cconf.h" +#include "dlhist.h" #include "proc-cache.h" #include "filter.h" #include "http.h" #include "rss.h" #define PROC_CACHE_PURGE_INTERVAL (60*60*6) /* 6 hours (in seconds) */ +#define DLHIST_PURGE_INTERVAL (60*60*24) /* 1 day */ static int write_http_file(struct http_file *file, const char *dest) { @@ -51,7 +53,8 @@ static void process_items(rss_t rss, struct target *t) { for(i=0; i < t->nr; i++) { struct filter *filter = &t->filter[i]; - if (!filter_match(filter->pattern, item.title)) + if (dlhist_lookup(item.title, filter->dest) || + !filter_match(filter->pattern, item.title)) continue; /* fetch the file if we haven't already. */ @@ -70,6 +73,7 @@ static void process_items(rss_t rss, struct target *t) { printf("Downloaded: %s (%s) to %s\n", item.title, item.link, filter->dest); + dlhist_mark(item.title, filter->dest); proc_cache_update(item.link); } @@ -83,6 +87,7 @@ static void process(struct cconf *config) { struct buffer *data; proc_cache_purge(PROC_CACHE_PURGE_INTERVAL); + dlhist_purge(DLHIST_PURGE_INTERVAL); for(i=0; i < config->nr; i++) { struct target *t = config->target + i; @@ -118,12 +123,14 @@ int main(int argc, char *argv[]) { return 1; } - if (proc_cache_open() < 0) + /* open process cache and download history. */ + if (proc_cache_open() < 0 || dlhist_open() < 0) return 1; process(config); proc_cache_close(); + dlhist_close(); cconf_free(config); return 0;