fix empty epg.db if regeneration coincides with raw EPG update

This commit is contained in:
hummypkg 2017-06-26 21:47:32 +00:00 committed by HummyPkg
parent abe92a3135
commit 000c750b19
3 changed files with 21 additions and 13 deletions

6
epg.c
View File

@ -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

2
lint.h
View File

@ -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 *);

26
main.c
View File

@ -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);