]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - indexonly.c
Generate redirector log even if -d is not given
[thirdparty/sarg.git] / indexonly.c
index 0c538a1a72a221b9668747653a4ef2ae83d899f5..b6d44bb00915f0f977b5b202f90110ff247be5b7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2010
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
 
 void index_only(const char *dirname,int debug)
 {
-   DIR *dirp;
-   struct dirent *direntp;
-   char remove[MAXLEN];
+       DIR *dirp;
+       struct dirent *direntp;
+       char remove[MAXLEN];
 
-   if ((dirp = opendir(dirname)) == NULL) {
-      debuga(_("Failed to open directory %s - %s\n"),dirname,strerror(errno));
-      exit(EXIT_FAILURE);
-   }
-   while ( (direntp = readdir( dirp )) != NULL ){
-      if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0 || strcmp(direntp->d_name, "index.html") == 0)
-         continue;
+       if ((dirp = opendir(dirname)) == NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),dirname,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       while ( (direntp = readdir( dirp )) != NULL ){
+               if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0 || strcmp(direntp->d_name, INDEX_HTML_FILE) == 0)
+                       continue;
 
-      if (snprintf(remove,sizeof(remove),"%s/%s",dirname,direntp->d_name)>=sizeof(remove)) {
-         debuga(_("Name of the file to remove is too long: %s/%s\n"),dirname,direntp->d_name);
-         continue;
-      }
-      if (unlink(remove) == -1) {
-         debuga(_("Failed to remove the file %s\n"),remove);
-      }
-   }
+               if (snprintf(remove,sizeof(remove),"%s/%s",dirname,direntp->d_name)>=sizeof(remove)) {
+                       debuga(__FILE__,__LINE__,_("Name of the file to remove is too long. File name is \"%s/%s\"\n"),dirname,direntp->d_name);
+                       continue;
+               }
+               if (unlink(remove) == -1) {
+                       debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),remove,strerror(errno));
+               }
+       }
 
-   (void)closedir( dirp );
+       (void)closedir( dirp );
 
-   return;
+       return;
 }