Mercurial > hg > Members > kono > nitros9-code
comparison 3rdparty/packages/uucpbb/src/expgroup.c @ 1772:5ba8e711a1a3
source added
author | boisy |
---|---|
date | Fri, 01 Apr 2005 22:04:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1771:7f2e75d5b62d | 1772:5ba8e711a1a3 |
---|---|
1 /* expgroup.c This routine deletes a newsgroup's old articles. | |
2 Copyright (C) 1990, 1993 Rick Adams and Bob Billson | |
3 | |
4 This file is part of the OS-9 UUCP package, UUCPbb. | |
5 | |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software | |
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 The author of UUCPbb, Bob Billson, can be contacted at: | |
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail: | |
22 21 Bates Way, Westfield, NJ 07090 | |
23 */ | |
24 | |
25 #include "uucp.h" | |
26 #include <modes.h> | |
27 #include <direct.h> | |
28 #include <time.h> | |
29 | |
30 #define BRUTE_LIMIT 32 /* EK */ | |
31 | |
32 extern QQ int expireflag, debuglvl; /* made direct page -- REB */ | |
33 extern QQ FILE *log; /* Added -- REB */ | |
34 extern char sender[]; /* */ | |
35 extern struct active groups[]; | |
36 | |
37 | |
38 int expgroup (grp, limit) | |
39 struct active *grp; | |
40 int limit; /* how many days old the article needs */ | |
41 { /* be before it is expired. */ | |
42 char filename[33]; | |
43 int age, min, mid, max; /* EK */ | |
44 register int i; | |
45 struct fildes finfo; | |
46 struct sgtbuf date; | |
47 | |
48 /* get today's date and time */ | |
49 getime (&date); | |
50 | |
51 /* expire articles */ | |
52 | |
53 /* Use brute force if less than BRUTE_LIMIT articles exist. */ | |
54 if (grp->seq - grp->index < BRUTE_LIMIT) | |
55 { | |
56 if (debuglvl > 3) | |
57 fputs ("expgroup: using brute-force to expire articles\n", | |
58 log); | |
59 | |
60 /* expire articles -- brute force, linear search */ | |
61 for (i = grp->index; i <= grp->seq; i++) | |
62 { | |
63 /* get filename */ | |
64 sprintf (filename, "a%d", i); | |
65 | |
66 if (debuglvl > 3) | |
67 fprintf (log, "expgroup: checking article %s\n", | |
68 filename); | |
69 | |
70 /* was the article already deleted? */ | |
71 if ((age = getage (filename, &date)) == ERROR) | |
72 { | |
73 if (debuglvl > 3) | |
74 fprintf (log, "expire: unable to get age of article: %s\n", | |
75 filename); | |
76 continue; | |
77 } | |
78 | |
79 if (age > limit) | |
80 { | |
81 if (debuglvl > 2) | |
82 fprintf (log, "%s %s expiring %s\n", | |
83 sender, gtime(), filename); | |
84 | |
85 if (expireflag) | |
86 unlink (filename); | |
87 else | |
88 fprintf (log, "article %s/%s would have been deleted\n", | |
89 grp->newsgroup, filename); | |
90 } | |
91 else | |
92 { | |
93 if (!expireflag) /* added --REB */ | |
94 fprintf (log, "article %s/%s too new\n", | |
95 grp->newsgroup, filename); | |
96 | |
97 break; /* Found first non-expirable file */ | |
98 } | |
99 } | |
100 } | |
101 else | |
102 { | |
103 /* expire articles -- binary search */ | |
104 min = grp->index; | |
105 max = grp->seq; | |
106 | |
107 if (debuglvl > 3) | |
108 fputs ("expgroup: using binary search to expire articles\n", | |
109 log); | |
110 | |
111 while (max - min > 1) | |
112 { | |
113 mid = min + (max - min)/2; | |
114 i = 0; | |
115 sprintf (filename, "a%d", mid); | |
116 | |
117 /* if midpoint file doesn't exist */ | |
118 while ((age = getage (filename, &date)) == ERROR | |
119 && mid - i > min) | |
120 { | |
121 if (debuglvl > 3) | |
122 fprintf (log, "expire: unable to get age of article: %s\n", | |
123 filename); | |
124 ++i; | |
125 sprintf (filename, "a%d", mid - i); | |
126 } | |
127 | |
128 if (age == ERROR) | |
129 age = 32767; /* No files between min and mid */ | |
130 | |
131 if (age > limit) /* would we expire this file? */ | |
132 min = mid; /* yes, search forward */ | |
133 else | |
134 max = mid; /* no, search backward */ | |
135 } | |
136 | |
137 if (debuglvl > 1) | |
138 fprintf (log, "expire: expiring articles %d to %d\n", | |
139 grp->index, min); | |
140 | |
141 /* Now delete all articles, grp->index to min */ | |
142 for (i = grp->index; i <= min; i++) | |
143 { | |
144 sprintf (filename, "a%d", i); | |
145 | |
146 if (debuglvl > 2) | |
147 fprintf (log, "expiring article: %s\n", filename); | |
148 | |
149 if (expireflag) | |
150 unlink (filename); | |
151 } | |
152 } | |
153 /* if deleting files, set lowest # index in active file */ | |
154 if (expireflag) | |
155 grp->index = i; | |
156 } | |
157 | |
158 | |
159 | |
160 /* getage -- return age of file 'filename' in days */ | |
161 | |
162 int getage (filename, date) | |
163 char *filename; | |
164 struct sgtbuf *date; | |
165 { | |
166 struct fildes finfo; | |
167 int path, stat, year, mon, day, age; | |
168 | |
169 /* get the file info sector */ | |
170 if ((path = open (filename, S_IREAD)) == -1) | |
171 return (ERROR); /* Must already be deleted */ | |
172 | |
173 stat = _gs_gfd (path, &finfo, sizeof (finfo)); | |
174 close (path); | |
175 | |
176 if (stat == ERROR) /* Error getting FD */ | |
177 return (ERROR); | |
178 | |
179 /* get file modification date and time */ | |
180 year = finfo.fd_date[0]; | |
181 mon = finfo.fd_date[1]; | |
182 day = finfo.fd_date[2]; | |
183 | |
184 /* how old is this article? */ | |
185 age = (date->t_year - year) * 365; | |
186 age += (date->t_month - mon) * 31; | |
187 age += (date->t_day - day); | |
188 | |
189 if (debuglvl > 2) | |
190 fprintf (log, "article %s age is %d days\n", filename, age); | |
191 | |
192 return (age); | |
193 } |