From 000c750b19ffa9dbd695427e6bb811540965d768 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 26 Jun 2017 21:47:32 +0000 Subject: [PATCH] fix empty epg.db if regeneration coincides with raw EPG update --- epg.c | 6 ++++-- lint.h | 2 +- main.c | 26 ++++++++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/epg.c b/epg.c index ac88a0b..09c20ed 100644 --- a/epg.c +++ b/epg.c @@ -178,7 +178,7 @@ check_filter(struct epgfilter *f, enum epgfiltertype type, return 1; } -void +int parse(char *epgpath, void (*callback)(struct epg *, struct section *, struct data *, struct descriptor **, void *), void *val, struct epgfilter *filter) @@ -188,7 +188,7 @@ parse(char *epgpath, int i; if (!(epg = open_file(epgpath))) - return; + return 0; while (epg->offset < epg->binsize) { @@ -439,6 +439,8 @@ parse(char *epgpath, } close_file(epg); + + return 1; } void diff --git a/lint.h b/lint.h index ff290cb..007ea82 100644 --- a/lint.h +++ b/lint.h @@ -36,7 +36,7 @@ void dump_section(struct section *); struct data *read_data(struct epg *); void dump_data(struct data *); -void parse(char *, +int parse(char *, void (*)(struct epg *, struct section *, struct data *, struct descriptor **, void *), void *, struct epgfilter *); diff --git a/main.c b/main.c index 4882cc4..92b559a 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,7 @@ #include "lint.h" int debug = 0; -const char *version = "1.2.6"; +const char *version = "1.2.7"; unsigned long sysopts = 0; unsigned long filterflags = 0; static time_t latest_stamp = 0; @@ -236,7 +236,7 @@ json_escape_len(unsigned int len, char *txt) exit(0); \ } while (0) -void +static void sqlitedumpstart(char *file) { char buf[MAXPATHLEN + 1]; @@ -282,8 +282,8 @@ sqlitedumpstart(char *file) } } -void -sqlitedumpend(char *file) +static void +sqlitedumpend(char *file, int commit) { char buf[MAXPATHLEN + 1]; char *error; @@ -293,8 +293,10 @@ sqlitedumpend(char *file) sqlite3_close(db); sprintf(buf, "%s.load", file); - /*unlink(file);*/ - rename(buf, file); + if (commit) + rename(buf, file); + else + unlink(buf); } void @@ -1050,9 +1052,11 @@ nextopt: #ifdef HAVE_SQLITE3 else if (!strcmp(argv[0], "sqlitedump") && argc == 2) { + int r; + sqlitedumpstart(argv[1]); - parse(epgpath, sqlitedump, NULL, filter); - sqlitedumpend(argv[1]); + r = parse(epgpath, sqlitedump, NULL, filter); + sqlitedumpend(argv[1], r); } else if (!strcmp(argv[0], "sqlitedumpd") && argc == 2) { @@ -1070,11 +1074,13 @@ nextopt: if (st.st_mtime > last) { time_t tm = time(NULL); + int r; + printf("epgd: Regenerating.\n"); fflush(stdout); sqlitedumpstart(argv[1]); - parse(epgpath, sqlitedump, NULL, filter); - sqlitedumpend(argv[1]); + r = parse(epgpath, sqlitedump, NULL, filter); + sqlitedumpend(argv[1], r); printf("epgd: Done in %ld seconds.\n", time(NULL) - tm); fflush(stdout);