mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-05-30 00:40:42 +00:00
Improve deletion of older logs
This commit is contained in:
parent
cf5a235008
commit
96f07b21de
2 changed files with 41 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
|||
2021-09-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* EcCommand.m: When deleting old logs, consider directories from all
|
||||
time rather than just those for the last year. This prevents logs
|
||||
from being left undeleted when the DeleteLogsAfter config is changed
|
||||
from a value longer than a year to a shorter value.
|
||||
|
||||
2021-06-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Command.m:
|
||||
|
|
52
EcCommand.m
52
EcCommand.m
|
@ -5796,29 +5796,45 @@ NSLog(@"Problem %@", localException);
|
|||
uncompressed = logUncompressed;
|
||||
undeleted = logUndeleted;
|
||||
}
|
||||
if (0.0 == undeleted)
|
||||
{
|
||||
undeleted = now - 365.0 * day;
|
||||
}
|
||||
ti = undeleted;
|
||||
latestDeleteAt = now - day * deleteAfter;
|
||||
while (ti < latestDeleteAt)
|
||||
if (undeleted < latestDeleteAt)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
NSDirectoryEnumerator *enumerator;
|
||||
NSString *file;
|
||||
NSCalendarDate *when;
|
||||
unsigned limit;
|
||||
|
||||
when = date(ti);
|
||||
file = [[dir stringByAppendingPathComponent:
|
||||
[when descriptionWithCalendarFormat: @"%Y-%m-%d"]]
|
||||
stringByStandardizingPath];
|
||||
if ([mgr fileExistsAtPath: file])
|
||||
when = date(latestDeleteAt);
|
||||
limit = ([when yearOfCommonEra] * 100 + [when monthOfYear]) * 100
|
||||
+ [when dayOfMonth];
|
||||
|
||||
enumerator = [mgr enumeratorAtPath: dir];
|
||||
while ((file = [enumerator nextObject]) != nil)
|
||||
{
|
||||
[mgr removeFileAtPath: file handler: nil];
|
||||
}
|
||||
ti += day;
|
||||
[pool release];
|
||||
if ([file length] == 10)
|
||||
{
|
||||
const char *s = [file UTF8String];
|
||||
unsigned y, m, d;
|
||||
|
||||
if (sscanf(s, "%04u-%02u-%02u", &y, &m, &d) == 3)
|
||||
{
|
||||
int dayNumber = (y * 100 + m) * 100 + d;
|
||||
|
||||
if (dayNumber < limit)
|
||||
{
|
||||
file = [dir stringByAppendingPathComponent: file];
|
||||
if (NO == [mgr removeFileAtPath: file handler: nil])
|
||||
{
|
||||
NSLog(@"Failed to delete old logs at %@", file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
undeleted = latestDeleteAt;
|
||||
}
|
||||
if (YES == deb) debUndeleted = ti;
|
||||
else logUndeleted = ti;
|
||||
if (YES == deb) debUndeleted = undeleted;
|
||||
else logUndeleted = undeleted;
|
||||
|
||||
if (uncompressed < undeleted)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue