-/*! \fn void vrfydir(const char *per1, const char *addr, const char *site, const char *us, const char *form)
-Create a directory to generate a report for the specified connection data and populate it with the a <tt>sarg-date</tt> file
-containing the current date.
-
-The function also create an <tt>images</tt> directory in \a dir and copy all the files from the <tt>SYSCONFDIR/images</tt> into
-that directory.
-
-\param per1 The date range in the form: YYYYMMMDD-YYYYMMMDD or DDMMMYYYY-DDMMMYYYY depending on the value of
-::DateFormat.
-\param addr The ip address or host name to which the report is limited. If the string is empty, all the addresses are accepted.
-\param site The destination site to which the report is limited. If the string is empty, all the sites are accepted.
-\param us The user to whom the report is limited. It is an empty string if all the users are accepted.
-\param form The email address to which the report is sent. It is currently unused.
-
-*/
-
-
-
-
-
/*! \fn void strip_latin(char *line)
Remove any HTML entity from the line. A HTML entity starts with an ampersand and end at the next
semicolon.
bool IsTreeYearFileName(const char *Name);
bool IsTreeMonthFileName(const char *Name);
bool IsTreeDayFileName(const char *Name);
-int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form);
+int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us);
int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period);
void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil);
void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate);
return(true);
}
-int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form)
+/*!
+ * Create a directory to generate a report for the specified connection data
+ * and populate it with the a <tt>sarg-date</tt> file containing the current
+ * date.
+ *
+ * The function also create an <tt>images</tt> directory in \a dir and copy all
+ * the files from the <tt>SYSCONFDIR/images</tt> into that directory.
+ *
+ * \param per1 The date range in the form: YYYYMMMDD-YYYYMMMDD or DDMMMYYYY-DDMMMYYYY depending on the value of
+ * ::DateFormat.
+ * \param addr The ip address or host name to which the report is limited. If the string is empty, all the addresses are accepted.
+ * \param site The destination site to which the report is limited. If the string is empty, all the sites are accepted.
+ * \param us The user to whom the report is limited. It is an empty string if all the users are accepted.
+ */
+int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us)
{
FILE *fp_ou;
- int num=1, count=0;
char wdir[MAXLEN];
- char dirname2[MAXLEN];
int y1, y2;
int m1, m2;
int d1, d2;
strcpy(outdirname,wdir);
- if(IndexTree != INDEX_TREE_DATE) {
- if(!OverwriteReport) {
- while(num) {
- if(access(wdir,R_OK) == 0) {
- sprintf(wdir,"%s.%d",outdirname,num);
- num++;
- count++;
- } else
- break;
- }
+ // manufacture a new unique name if configured to keep old reports or overwrite old report if configured to do so
+ if (!OverwriteReport) {
+ int num=1;
- if(count > 0) {
- if(debug)
- debuga(__FILE__,__LINE__,_("File %s already exists, moved to %s\n"),outdirname,wdir);
- rename(outdirname,wdir);
- }
- } else {
- if(access(outdirname,R_OK) == 0) {
- unlinkdir(outdirname,1);
- }
+ while (access(wdir,R_OK)==0 || errno==EACCES) //file exist or can't be read
+ {
+ sprintf(wdir,"%s.%d",outdirname,num);
+ num++;
+ }
+ if (num>1) {
+ if(debug)
+ debuga(__FILE__,__LINE__,_("File %s already exists, moved to %s\n"),outdirname,wdir);
+ rename(outdirname,wdir);
}
- my_mkdir(outdirname);
} else {
- strcpy(dirname2,wdir);
- if(!OverwriteReport) {
- while(num) {
- if(access(wdir,R_OK) == 0) {
- sprintf(wdir,"%s.%d",dirname2,num);
- num++;
- count++;
- } else
- break;
- }
-
- if(count > 0) {
- if(debug)
- debuga(__FILE__,__LINE__,_("File %s already exists, moved to %s\n"),dirname2,wdir);
- rename(dirname2,wdir);
- strcpy(dirname2,wdir);
- }
- } else {
- if(access(wdir,R_OK) == 0) {
- unlinkdir(wdir,1);
- }
+ if(access(outdirname,R_OK) == 0) {
+ unlinkdir(outdirname,1);
}
-
- if(access(wdir, R_OK) != 0)
- my_mkdir(wdir);
}
+ my_mkdir(outdirname);
- strcpy(dirname2,wdir);
-
+ // create sarg-date to keep track of the report creation date
if (snprintf(wdir,sizeof(wdir),"%s/sarg-date",outdirname)>=sizeof(wdir)) {
debuga(__FILE__,__LINE__,_("Buffer too small to store "));
debuga_more("%s/sarg-date",outdirname);