From: Frédéric Marchal Date: Fri, 25 Feb 2011 20:32:09 +0000 (+0000) Subject: Don't abort for an empty report directory X-Git-Tag: v2.3.2~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15d3cb5c87454a3bce9cca6889aa5aa9690d9842;p=thirdparty%2Fsarg.git Don't abort for an empty report directory If sarg fails and leaves an empty report directory, one without a sarg-date file in it, any subsequent execution of sarg will fail due to that empty report directory. This change ignores such an empty directory and issue a simple warning. --- diff --git a/documentation/util.txt b/documentation/util.txt index 70a5b8c..73683f6 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -358,19 +358,6 @@ Write the elapsed time given in milliseconds as a string in the format HH:MM:SS. -/*! \fn void obtdate(const char *dirname, const char *name, char *data) -Get the date stored in the sarg-date file of a directory with the connection data. - -\param dirname The directory to look for the connection directory. -\param name The name of the directory whose sarg-date file must be read. -\param data The buffer to store the content of the file. It must be more than 80 -bytes long. -*/ - - - - - /*! \fn void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst) Format a date to display it in the report. diff --git a/include/defs.h b/include/defs.h index de69ec5..20ba906 100755 --- a/include/defs.h +++ b/include/defs.h @@ -250,7 +250,7 @@ void url_module(const char *url, char *w2); void url_to_file(const char *url,char *file,int filesize); void strip_latin(char *line); char *buildtime(long long int elap); -void obtdate(const char *dirname, const char *name, char *data); +int obtdate(const char *dirname, const char *name, char *data); void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst); void computedate(int year,int month,int day,struct tm *t); int obtuser(const char *dirname, const char *name); diff --git a/index.c b/index.c index cb508da..651ef1b 100644 --- a/index.c +++ b/index.c @@ -336,6 +336,10 @@ static void make_file_index(void) sortlist=NULL; while ((direntp = readdir( dirp )) != NULL) { if (strchr(direntp->d_name,'-') == 0) continue; + if (obtdate(outdir,direntp->d_name,data)<0) { + debuga(_("The directory \"%s%s\" looks like a report directory but doesn't contain a sarg-date file. You should delete it\n"),outdir,direntp->d_name); + continue; + } item=malloc(sizeof(*item)); if (!item) { debuga(_("not enough memory to sort the index\n")); @@ -351,7 +355,6 @@ static void make_file_index(void) item->day=atoi(direntp->d_name); } item->sortnum=(item->year*16+item->month)*32+item->day; - obtdate(outdir,direntp->d_name,data); if (sscanf(data,"%d-%d-%d %d:%d:%d %d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond,&idst)==7) { formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond,idst); snprintf(item->creationdate,sizeof(item->creationdate),"%04d%02d%02d%02d%02d%02d",iyear,imonth,iday,ihour,iminute,isecond); diff --git a/util.c b/util.c index 1efde0e..189a82c 100644 --- a/util.c +++ b/util.c @@ -572,7 +572,18 @@ char *buildtime(long long int elap) } -void obtdate(const char *dirname, const char *name, char *data) +/*! +Get the date stored in the sarg-date file of a directory with the connection data. + +\param dirname The directory to look for the connection directory. +\param name The name of the directory whose sarg-date file must be read. +\param data The buffer to store the content of the file. It must be more than 80 +bytes long. + +\retval 0 No error. +\retval -1 File not found. +*/ +int obtdate(const char *dirname, const char *name, char *data) { FILE *fp_in; char wdir[MAXLEN]; @@ -582,7 +593,7 @@ void obtdate(const char *dirname, const char *name, char *data) sprintf(wdir,"%s%s/date",dirname,name); if ((fp_in = fopen(wdir, "rt")) == 0) { data[0]='\0'; - return; + return(-1); } } @@ -593,7 +604,7 @@ void obtdate(const char *dirname, const char *name, char *data) fclose(fp_in); fixendofline(data); - return; + return(0); }