/*
- * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
- * 1998, 2010
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ * http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
void index_only(const char *dirname,int debug)
{
- DIR *dirp;
- struct dirent *direntp;
- char remove[MAXLEN];
-
- dirp = opendir(dirname);
- while ( (direntp = readdir( dirp )) != NULL ){
- if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0 || strcmp(direntp->d_name, "index.html") == 0)
- continue;
-
- sprintf(remove,"%s/%s",dirname,direntp->d_name);
- unlink(remove);
- }
+ DIR *dirp;
+ struct dirent *direntp;
+ char remove[MAXLEN];
- (void)closedir( dirp );
+ 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;
- return;
+ 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 );
+
+ return;
}