From: Frederic Marchal Date: Sun, 12 Jul 2015 19:13:43 +0000 (+0200) Subject: Make it possible to delete an old temporary directory X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d04f0729c876ae29b2866a82d38cd657ed1c7f4;p=thirdparty%2Fsarg.git Make it possible to delete an old temporary directory Sarg prepares the report in a the temporary directory. The directory must be empty before starting the report generation. Deleting an old stray temporary directory must be made with care to make sure we don't delete a wrong directory. The old temporary directory check would not take the email report generated files into account. --- diff --git a/email.c b/email.c index 293601a..6e46807 100644 --- a/email.c +++ b/email.c @@ -63,7 +63,7 @@ int geramail(const char *dirname, int debug, const char *email, const char *Temp exit(EXIT_FAILURE); } - snprintf(top2,sizeof(top2),"%s/top.tmp",dirname); + snprintf(top2,sizeof(top2),"%s/email.int_unsort",dirname); if((fp_top2=fopen(top2,"w"))==NULL) { debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top2,strerror(errno)); exit(EXIT_FAILURE); diff --git a/report.c b/report.c index e1df5ba..acf37fe 100644 --- a/report.c +++ b/report.c @@ -94,9 +94,18 @@ void gerarel(void) smartfilter=false; memset(&globstat,0,sizeof(globstat)); - if (vrfydir(&period, addr, site, us)<0) { - debuga(__FILE__,__LINE__,_("Cannot create the output directory name containing the period as part of the name\n")); - exit(EXIT_FAILURE); + if (email[0]=='\0') { + if (vrfydir(&period, addr, site, us)<0) { + debuga(__FILE__,__LINE__,_("Cannot create the output directory name containing the period as part of the name\n")); + exit(EXIT_FAILURE); + } + } else { + if (snprintf(outdirname,sizeof(outdirname),"%semailrep",outdir)>=sizeof(outdirname)) { + debuga(__FILE__,__LINE__,_("Path too long: ")); + debuga_more("%semailrep\n",outdir); + exit(EXIT_FAILURE); + } + my_mkdir(outdirname); } if(debugz>=LogLevel_Process){ diff --git a/util.c b/util.c index c49824e..dc75be0 100644 --- a/util.c +++ b/util.c @@ -2266,7 +2266,8 @@ void emptytmpdir(const char *dir) ".utmp", ".ip", "lastlog1", - "lastlog" + "lastlog", + "emailrep" }; dirp=opendir(dir);