Archived
1
0
Fork 0

make dlight.c use the new dlhist

This commit is contained in:
Henrik Hautakoski 2011-12-15 13:35:13 +01:00
parent 40e6afeffa
commit 37ba894802
3 changed files with 12 additions and 5 deletions

View file

@ -11,7 +11,7 @@ install : $(PROGRAMS)
cp $^ $(HOME)/bin/ cp $^ $(HOME)/bin/
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \ 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-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-read-config : read-config.o buffer.o env.o cconf.o error.o
dlight-filter-check: filter-check.o filter.o error.o dlight-filter-check: filter-check.o filter.o error.o

View file

@ -68,7 +68,7 @@ static unsigned hash(const char *s) {
unsigned h; unsigned h;
for(h = 0; *s; s++) for(h = 0; *s; s++)
h = ((unsigned)*s) + (h << 6) + (h << 16) - h; h = ((unsigned)*s) + (h << 6) + (h << 16) - h;
return 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) if (stat(a, &sa) < 0 || stat(b, &sb) < 0)
return 0; return 0;
return sa.st_dev == sb.st_dev && return sa.st_dev == sb.st_dev &&
sa.st_ino == sb.st_ino; sa.st_ino == sb.st_ino;
} }

View file

@ -9,12 +9,14 @@
#include "env.h" #include "env.h"
#include "error.h" #include "error.h"
#include "cconf.h" #include "cconf.h"
#include "dlhist.h"
#include "proc-cache.h" #include "proc-cache.h"
#include "filter.h" #include "filter.h"
#include "http.h" #include "http.h"
#include "rss.h" #include "rss.h"
#define PROC_CACHE_PURGE_INTERVAL (60*60*6) /* 6 hours (in seconds) */ #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) { 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++) { for(i=0; i < t->nr; i++) {
struct filter *filter = &t->filter[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; continue;
/* fetch the file if we haven't already. */ /* 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", printf("Downloaded: %s (%s) to %s\n",
item.title, item.link, filter->dest); item.title, item.link, filter->dest);
dlhist_mark(item.title, filter->dest);
proc_cache_update(item.link); proc_cache_update(item.link);
} }
@ -83,6 +87,7 @@ static void process(struct cconf *config) {
struct buffer *data; struct buffer *data;
proc_cache_purge(PROC_CACHE_PURGE_INTERVAL); proc_cache_purge(PROC_CACHE_PURGE_INTERVAL);
dlhist_purge(DLHIST_PURGE_INTERVAL);
for(i=0; i < config->nr; i++) { for(i=0; i < config->nr; i++) {
struct target *t = config->target + i; struct target *t = config->target + i;
@ -118,12 +123,14 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
if (proc_cache_open() < 0) /* open process cache and download history. */
if (proc_cache_open() < 0 || dlhist_open() < 0)
return 1; return 1;
process(config); process(config);
proc_cache_close(); proc_cache_close();
dlhist_close();
cconf_free(config); cconf_free(config);
return 0; return 0;