From: Frédéric Marchal Date: Mon, 4 Jan 2010 11:46:30 +0000 (+0000) Subject: Fix recursive directory deletion. X-Git-Tag: v2_2_7~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0511cf2d29a0e256e120a8491e31048bd2493ead;p=thirdparty%2Fsarg.git Fix recursive directory deletion. Detect and re-read old sarg-general files with space separated columns. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index afac3fc..edc56fb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "7rc1") -SET(sarg_BUILDDATE "Jan-03-2010") +SET(sarg_BUILDDATE "Jan-04-2010") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/getconf.c b/getconf.c index a6adbfa..ea57749 100644 --- a/getconf.c +++ b/getconf.c @@ -289,7 +289,7 @@ static void parmtest(char *buf) return; } - if (getparam_string("lastlog",buf,LastLog,sizeof(LastLog))>0) return; + if (getparam_int("lastlog",buf,&LastLog)>0) return; if (getparam_bool("remove_temp_files",buf,&RemoveTempFiles)>0) return; diff --git a/include/conf.h b/include/conf.h index 416a77e..efa0caa 100755 --- a/include/conf.h +++ b/include/conf.h @@ -165,7 +165,7 @@ char day[3], month[4], year[5]; char ltext110[50]; char cdfrom[30]; char cduntil[30]; -char LastLog[5]; +int LastLog; int RemoveTempFiles; char ReplaceIndex[256]; char Index[20]; diff --git a/include/info.h b/include/info.h index e894c49..8066b64 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Jan-03-2010" +#define VERSION PACKAGE_VERSION" Jan-04-2010" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/index.c b/index.c index ffd57c5..838ba04 100644 --- a/index.c +++ b/index.c @@ -37,7 +37,7 @@ void make_index(void) struct dirent *direntp; char wdir[MAXLEN]; - if(LastLog[0] != '\0') mklastlog(outdir); + if(LastLog > 0) mklastlog(outdir); if(strcmp(Index,"no") == 0) { sprintf(wdir,"%sindex.html",outdir); diff --git a/lastlog.c b/lastlog.c index 31fea55..de9cbac 100644 --- a/lastlog.c +++ b/lastlog.c @@ -42,7 +42,7 @@ void mklastlog(const char *outdir) int cstatus; struct getwordstruct gwarea; - if(strcmp(LastLog,"0") == 0) + if(LastLog <= 0) return; sprintf(temp,"%slastlog1",outdir); @@ -78,14 +78,14 @@ void mklastlog(const char *outdir) unlink(temp); - if(ftot<=atoi(LastLog)) { + if(ftot<=LastLog) { sprintf(temp,"%slastlog",outdir); if(access(temp, R_OK) == 0) unlink(temp); return; } - ftot-=atoi(LastLog); + ftot-=LastLog; sprintf(temp,"%slastlog",outdir); if((fp_in=fopen(temp,"r"))==NULL) { diff --git a/log.c b/log.c index c3dff13..f6d9f58 100644 --- a/log.c +++ b/log.c @@ -144,7 +144,7 @@ int main(int argc,char *argv[]) ExcludeUsers[0]='\0'; ConfigFile[0]='\0'; code[0]='\0'; - LastLog[0]='\0'; + LastLog=0; ReportType[0]='\0'; UserTabFile[0]='\0'; BlockIt[0]='\0'; diff --git a/util.c b/util.c index 571866a..af5b976 100644 --- a/util.c +++ b/util.c @@ -720,34 +720,43 @@ void obttotal(const char *dirname, const char *name, char *tbytes, const char *t char buf[MAXLEN]; char wdir[MAXLEN]; char warea[MAXLEN]; + char sep; long long int med=0; long long int wtuser=0; long long int twork=0; struct getwordstruct gwarea; + twork=0; + tbytes[0]='\0'; + media[0]='\0'; + sprintf(wdir,"%s%s/sarg-general",dirname,name); if ((fp_in = fopen(wdir, "r")) == 0) { sprintf(wdir,"%s%s/general",dirname,name); if ((fp_in = fopen(wdir, "r")) == 0) { - tbytes[0]='\0'; - media[0]='\0'; return; } } while(fgets(buf,sizeof(buf),fp_in)!=NULL) { + if (strncmp(buf,"TOTAL\t",6) == 0) + sep='\t'; //new file + else if (strncmp(buf,"TOTAL ",6) == 0) + sep=' '; //old file + else + continue; getword_start(&gwarea,buf); - if (getword(warea,sizeof(warea),&gwarea,'\t')<0) { + if (getword(warea,sizeof(warea),&gwarea,sep)<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir); exit(1); } if(strcmp(warea,"TOTAL") != 0) continue; - if (getword_skip(MAXLEN,&gwarea,'\t')<0) { + if (getword_skip(MAXLEN,&gwarea,sep)<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir); exit(1); } - if (getword_atoll(&twork,&gwarea,'\t')<0) { + if (getword_atoll(&twork,&gwarea,sep)<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir); exit(1); } @@ -757,7 +766,7 @@ void obttotal(const char *dirname, const char *name, char *tbytes, const char *t fclose(fp_in); wtuser=my_atoll(tuser); - if(wtuser == 0) { + if(wtuser <= 0) { strcpy(media,"0"); return; } @@ -1644,7 +1653,7 @@ void unlinkdir(const char *dir,int contentonly) exit(1); } } else if (S_ISDIR(st.st_mode)) { - unlinkdir(dname,1); + unlinkdir(dname,0); } else { fprintf(stderr,"SARG: unknown path type %s\n",dname); }