From e3e6aef4790130e354269e077f31ad21dd54bd89 Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Mon, 3 Jun 2013 14:58:50 +0200 Subject: [PATCH] Don't generate the date/time report page if it isn't used 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 | 11 ++--------- include/defs.h | 1 + repday.c | 3 ++- topuser.c | 12 +++--------- totday.c | 21 +++++++++++++++++++++ 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/grepday.c b/grepday.c index d415fa4..302d8c8 100644 --- 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"); diff --git a/include/defs.h b/include/defs.h index 1910f40..6760806 100755 --- a/include/defs.h +++ b/include/defs.h @@ -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); diff --git a/repday.c b/repday.c index 712cfcc..af8e8f9 100644 --- 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); } diff --git a/topuser.c b/topuser.c index ebeda88..01015b5 100644 --- a/topuser.c +++ b/topuser.c @@ -343,9 +343,6 @@ void topuser(void) } uinfo->topuser=1; - report_day(uinfo); - greport_day(uinfo); - fputs("",fp_top3); posicao++; @@ -357,17 +354,14 @@ void topuser(void) fputs("",fp_top3); #ifdef HAVE_GD if(Graphs && GraphFont[0]!='\0') { + greport_day(uinfo); //fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); } #endif + report_day(uinfo); fprintf(fp_top3,"\"T\"",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) { diff --git a/totday.c b/totday.c index e2cee78..0ebf46b 100644 --- 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)); +} + -- 2.39.5