]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't abort for an empty report directory
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 25 Feb 2011 20:32:09 +0000 (20:32 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 25 Feb 2011 20:32:09 +0000 (20:32 +0000)
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.

documentation/util.txt
include/defs.h
index.c
util.c

index 70a5b8ca71ec82d325b5fdcab641ea17d6f33217..73683f657f887c04de66f2fbf09c84c9c8fe1153 100644 (file)
@@ -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 <tt>sarg-date</tt> 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 <tt>sarg-date</tt> 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.
 
index de69ec5ae1d874fd8485a3a758b3899e6787fe02..20ba9067ffe3a8d9758debf2555758d6da15a3f2 100755 (executable)
@@ -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 cb508da1f9c0b9fcaa6557b9940dd6d3dd88c963..651ef1b90264544d53b975c86c4cbbad3c84292b 100644 (file)
--- 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 1efde0e0d50e4445aded9a98090c239ab6853b93..189a82c963ba29406731d1a0b0ff2b0960198d88 100644 (file)
--- 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 <tt>sarg-date</tt> 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 <tt>sarg-date</tt> 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);
 }