56 entry=malloc(
sizeof(*entry));
58 debuga(__FILE__,__LINE__,
_(
"Not enough memory to store a report to purge\n"));
62 entry->
Name=malloc((NameLen+1)*
sizeof(
char));
65 debuga(__FILE__,__LINE__,
_(
"Not enough memory to store a report to purge\n"));
69 entry->
Time=CreationTime;
74 for (ptr=List ; ptr ; ptr=ptr->
Next)
76 if (ptr->
Time>CreationTime)
break;
91 struct dirent *direntp;
95 if ((dirp = opendir(Path)) == NULL) {
96 debuga(__FILE__,__LINE__,
_(
"Cannot open directory \"%s\": %s\n"),Path,strerror(errno));
99 while ((direntp = readdir( dirp )) != NULL )
101 name_len=strlen(direntp->d_name);
102 if (RootPos+name_len+1>=PathSize) {
103 debuga(__FILE__,__LINE__,
_(
"Directory entry \"%s%s\" too long to purge the old reports\n"),Path,direntp->d_name);
106 strcpy(Path+Length,direntp->d_name);
107 if (stat(Path,&statb) == -1) {
108 debuga(__FILE__,__LINE__,
_(
"Failed to get the statistics of file \"%s\": %s\n"),Path,strerror(errno));
111 if (!S_ISDIR(statb.st_mode))
continue;
116 Path[Length+name_len]=
'/';
117 Path[Length+name_len+1]=
'\0';
121 debuga(__FILE__,__LINE__,
_(
"Old reports deletion not undertaken due to previous error\n"));
130 List=
AppendDirEntry(List,statb.st_mtime,Path+RootPos,Length-RootPos+name_len);
133 debuga(__FILE__,__LINE__,
_(
"Old reports deletion not undertaken due to previous error\n"));
147 struct dirent *direntp;
154 name_pos=strlen(Path);
155 if (name_pos>=
sizeof(
warea)) {
156 debuga(__FILE__,__LINE__,
_(
"The directory name \"%s\" containing the old reports to purge is too long\n"),Path);
160 if ((dirp = opendir(
outdir)) == NULL) {
161 debuga(__FILE__,__LINE__,
_(
"Cannot open directory \"%s\": %s\n"),
outdir,strerror(errno));
164 while ((direntp = readdir( dirp )) != NULL )
166 name_len=strlen(direntp->d_name);
167 if (name_pos+name_len+1>=
sizeof(
warea)) {
168 debuga(__FILE__,__LINE__,
_(
"Directory entry \"%s%s\" too long to purge the old reports\n"),Path,direntp->d_name);
171 strcpy(
warea+name_pos,direntp->d_name);
172 if (stat(
warea,&statb) == -1) {
173 debuga(__FILE__,__LINE__,
_(
"Failed to get the statistics of file \"%s\": %s\n"),
warea,strerror(errno));
176 if (!S_ISDIR(statb.st_mode))
continue;
179 List=
AppendDirEntry(List,statb.st_mtime,direntp->d_name,name_len);
182 debuga(__FILE__,__LINE__,
_(
"Old reports deletion not undertaken due to previous error\n"));
188 warea[name_pos+name_len]=
'/';
189 warea[name_pos+name_len+1]=
'\0';
193 debuga(__FILE__,__LINE__,
_(
"Old reports deletion not undertaken due to previous error\n"));
207 struct dirent *direntp;
210 while ((Dir=strrchr(Path,
'/'))!=NULL)
212 if (Dir-Path<=BasePos)
break;
214 if ((dirp = opendir(Path)) == NULL) {
215 debuga(__FILE__,__LINE__,
_(
"Cannot open directory \"%s\": %s\n"),Path,strerror(errno));
219 while ((direntp = readdir( dirp )) != NULL )
221 if (direntp->d_name[0]==
'.' && (direntp->d_name[1]==
'\0' || (direntp->d_name[1]==
'.' && direntp->d_name[2]==
'\0')))
continue;
235 debuga(__FILE__,__LINE__,
_(
"Deleting empty directory \"%s\"\n"),Path);
242 if (unlink(Path)==-1) {
243 debuga(__FILE__,__LINE__,
_(
"Failed to delete \"%s\": %s\n"),Path,strerror(errno));
249 debuga(__FILE__,__LINE__,
_(
"Cannot delete \"%s\": %s\n"),Path,strerror(errno));
270 for (ptr=List ; ptr ; ptr=ptr->
Next) ftot++;
272 debuga(__FILE__,__LINE__,
ngettext(
"%d report directory found\n",
"%d report directories found\n",ftot),ftot);
277 debuga(__FILE__,__LINE__,
ngettext(
"No old reports to delete as only %d report currently exists\n",
278 "No old reports to delete as only %d reports currently exist\n",ftot),ftot);
285 debuga(__FILE__,__LINE__,
ngettext(
"%d old report to delete\n",
"%d old reports to delete\n",ftot),ftot);
288 if (name_pos>=
sizeof(
warea)) {
290 debuga(__FILE__,__LINE__,
_(
"The directory name \"%s\" containing the old reports to purge is too long\n"),
outdir);
294 for (ptr=List ; ptr && ftot>0 ; ptr=ptr->
Next)
297 debuga(__FILE__,__LINE__,
_(
"Removing old report file %s\n"),ptr->
Name);
298 if (name_pos+strlen(ptr->
Name)+1>=
sizeof(
warea)) {
300 debuga(__FILE__,__LINE__,
_(
"Path too long: "));