]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix recursive directory deletion.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 4 Jan 2010 11:46:30 +0000 (11:46 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 4 Jan 2010 11:46:30 +0000 (11:46 +0000)
Detect and re-read old sarg-general files with space separated columns.

CMakeLists.txt
getconf.c
include/conf.h
include/info.h
index.c
lastlog.c
log.c
util.c

index afac3fc37f0265c253a8ef7550436edb1a43510d..edc56fb15f6b3fde9fc3d6911165dc457ccb32e3 100755 (executable)
@@ -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)
index a6adbfaa78dbe8c4991e1a28682de2bbe3102323..ea57749676f4cbd9763a8b578b0a8b9bbd5a96c5 100644 (file)
--- 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;
 
index 416a77e2bd353659bbb0af512c70dad0cbe9aa7b..efa0caa353640f7cedc274615076fea12f71c3bf 100755 (executable)
@@ -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];
index e894c49fc93c7da3755c5a2e9046ec327373ae5e..8066b641eac2b856eb8b9816c7290385db192379 100755 (executable)
@@ -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 ffd57c595a2d7a68d160bd805cf13c7e52954ce5..838ba04376559c0fd5b1993110ba652ff7be5469 100644 (file)
--- 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);
index 31fea55347685ee0cb91e19437eba60918c5cfe6..de9cbac67ade04138de761010af4ce6fa1f8a6c1 100644 (file)
--- 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 c3dff1305fb4102cbca41bdff8536471a729a224..f6d9f58344722aebc8e987c7ae355174009bae5d 100644 (file)
--- 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 571866a69911002c4f1c47092eaf54b02d58d3c3..af5b9765502a5032aefaec825b145e4a65268ba5 100644 (file)
--- 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);
       }