]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't generate the date/time report page if it isn't used
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 3 Jun 2013 12:58:50 +0000 (14:58 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 3 Jun 2013 12:58:50 +0000 (14:58 +0200)
The temporary file may still be created but it will be deleted before sarg
exits.

As a consequence, if temporary files are kept, the temporary directory may
hold more files than were actually used.

grepday.c
include/defs.h
repday.c
topuser.c
totday.c

index d415fa49748c3c5866fe94d7571ff9bcbd6447cf..302d8c89c71f977369576a3c2ab010cc3fd87a56 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -672,6 +672,8 @@ void greport_day(const struct userinfostruct *uinfo)
        struct getwordstruct gwarea;
        struct PlotStruct pdata;
 
+       if (datetimeby==0) return;
+       if (!Graphs || GraphFont[0]=='\0') return;
        if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
                debuga(_("user name too long for %s/%s.day\n"),tmp,uinfo->filename);
                exit(EXIT_FAILURE);
@@ -679,11 +681,6 @@ void greport_day(const struct userinfostruct *uinfo)
        if(access(wdirname, R_OK) != 0) {
                return;
        }
-       if(!Graphs || GraphFont[0]=='\0') {
-               if (!KeepTempLog && unlink(wdirname))
-                       debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(errno));
-               return;
-       }
 
        if((fp_in=fopen(wdirname,"r"))==NULL) {
                debuga(_("(grepday) Cannot open log file %s: %s\n"),wdirname,strerror(errno));
@@ -721,10 +718,6 @@ void greport_day(const struct userinfostruct *uinfo)
                }
        }
        fclose(fp_in);
-       if (!KeepTempLog && unlink(wdirname)) {
-               debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(errno));
-               exit(EXIT_FAILURE);
-       }
 
        if (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinfo->filename)>=sizeof(wdirname)) {
                debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,"graph.html");
index 1910f40b3d2817660d3a68e3b12b7fd231940414..676080656e512292233395c00c741ffc0bf49dc1 100755 (executable)
@@ -263,6 +263,7 @@ void day_cleanup(DayObject ddata);
 void day_newuser(DayObject ddata);
 void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes);
 void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *uinfo);
+void day_deletefile(const struct userinfostruct *uinfo);
 
 // url.c
 void read_hostalias(const char *Filename);
index 712cfcce94997be03dda2df982d812092b6bec6b..af8e8f9516322f6e556ec019e2ed33159b555176 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -57,6 +57,7 @@ void report_day(const struct userinfostruct *uinfo)
        struct getwordstruct gwarea;
        struct tm t;
 
+       if (datetimeby==0) return;
        snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
        if(access(wdirname, R_OK) != 0) return;
 
@@ -119,7 +120,7 @@ void report_day(const struct userinfostruct *uinfo)
        fclose(fp_in);
 
        if((fp_ou=fopen(arqout,"w"))==NULL) {
-               debuga(_("(repday) Cannot open log file %s: %s\n"),arqout,strerror(errno));
+               debuga(_("(repday) Cannot open output file %s: %s\n"),arqout,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
index ebeda88e7a33e93b4a36fd683cc369a0b02c03a9..01015b5c1e54abae4321baf4c28256e962b6df65 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -343,9 +343,6 @@ void topuser(void)
                }
                uinfo->topuser=1;
 
-               report_day(uinfo);
-               greport_day(uinfo);
-
                fputs("<tr>",fp_top3);
 
                posicao++;
@@ -357,17 +354,14 @@ void topuser(void)
                                fputs("<td class=\"data2\">",fp_top3);
 #ifdef HAVE_GD
                                if(Graphs && GraphFont[0]!='\0') {
+                                       greport_day(uinfo);
                                        //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
                                        fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
                                }
 #endif
+                               report_day(uinfo);
                                fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,uinfo->filename,ImageFile,_("date/time report"));
-                       } else {
-                               sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename);
-                               if (unlink(val1)) {
-                                       debuga(_("Cannot delete \"%s\": %s\n"),val1,strerror(errno));
-                                       exit(EXIT_FAILURE);
-                               }
+                               day_deletefile(uinfo);
                        }
                }
                if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
index e2cee78b6bbfca4fc03ec1fe541ea3a0a1d97a79..0ebf46bd3308eb73a89f9e2cc3871014afeabf0e 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -184,3 +184,24 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *
        }
        return;
 }
+
+/*!
+Delete the temporary file generated by day_totalize().
+
+\param uinfo The user whose daily statistics are to be deleted.
+*/
+void day_deletefile(const struct userinfostruct *uinfo)
+{
+       char arqout[2048];
+
+       if (KeepTempLog) return;
+
+       if (snprintf(arqout,sizeof(arqout),"%s/%s.day",tmp,uinfo->filename)>=sizeof(arqout)) {
+               debuga(_("File name too long: %s/%s%s\n"),tmp,uinfo->filename,".day");
+               exit(EXIT_FAILURE);
+       }
+
+       if (unlink(arqout))
+               debuga(_("Cannot delete temporary day file \"%s\": %s\n"),arqout,strerror(errno));
+}
+