]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - datafile.c
Get the file size with the available stat member
[thirdparty/sarg.git] / datafile.c
index a0339c8d3e72f82eacf8ef8aa1fbdab8c8c3ade6..1d4193c324c5ecb759ef780b3f4d524f82ec5473 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2013
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -44,6 +44,7 @@ void data_file(char *tmp)
        char *str;
        char tmp3[MAXLEN];
        char u2[MAX_USER_LEN];
+       char userlabel[MAX_USER_LEN];
        userscan uscan;
        long long int nbytes=0;
        long long int nelap=0;
@@ -79,17 +80,18 @@ void data_file(char *tmp)
                        ip2name(u2,sizeof(u2));
                        strcpy(nameantes,u2);
                }
-               user_find(uinfo->label,MAX_USER_LEN, u2);
+               user_find(userlabel,MAX_USER_LEN, u2);
+               userinfo_label(uinfo,userlabel);
                if(debug) debuga(_("Reading user file: %s/%s\n"),tmp,uinfo->filename);
 
                sort_users_log(tmp,debug,uinfo);
-               if (snprintf(tmp3,sizeof(tmp3),"%s/%s.log",tmp,uinfo->filename)>=sizeof(tmp3)) {
-                       debuga(_("(datafile) directory path too long: %s/%s.log\n"),tmp,uinfo->filename);
+               if (snprintf(tmp3,sizeof(tmp3),"%s/%s.user_log",tmp,uinfo->filename)>=sizeof(tmp3)) {
+                       debuga(_("(datafile) directory path too long: %s/%s.user_log\n"),tmp,uinfo->filename);
                        exit(EXIT_FAILURE);
                }
 
                if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
-                       debuga(_("(datafile) Cannot open file %s\n"),tmp3);
+                       debuga(_("(datafile) Cannot open file %s: %s\n"),tmp3,strerror(errno));
                        exit(EXIT_FAILURE);
                }
 
@@ -145,7 +147,7 @@ void data_file(char *tmp)
 
                        if(!same_url || new_user){
                                if(!fp_ou && (fp_ou=MY_FOPEN(DataFile,"w"))==NULL){
-                                       debuga(_("(datafile) Cannot open file %s\n"),DataFile);
+                                       debuga(_("(datafile) Cannot open file %s: %s\n"),DataFile,strerror(errno));
                                        exit(EXIT_FAILURE);
                                }
                                saverecs(fp_ou,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
@@ -192,7 +194,10 @@ void data_file(char *tmp)
        }
        userinfo_stopscan(uscan);
        if (oldurl) free(oldurl);
-       if (fp_ou) fclose(fp_ou);
+       if (fp_ou && fclose(fp_ou)==EOF) {
+               debuga(_("Write error in %s: %s\n"),DataFile,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if(debug)
                debuga(_("Datafile %s written successfully\n"),DataFile);