mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-05-31 01:10:55 +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>
|
2021-06-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Command.m:
|
* Command.m:
|
||||||
|
|
52
EcCommand.m
52
EcCommand.m
|
@ -5796,29 +5796,45 @@ NSLog(@"Problem %@", localException);
|
||||||
uncompressed = logUncompressed;
|
uncompressed = logUncompressed;
|
||||||
undeleted = logUndeleted;
|
undeleted = logUndeleted;
|
||||||
}
|
}
|
||||||
if (0.0 == undeleted)
|
|
||||||
{
|
|
||||||
undeleted = now - 365.0 * day;
|
|
||||||
}
|
|
||||||
ti = undeleted;
|
|
||||||
latestDeleteAt = now - day * deleteAfter;
|
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);
|
when = date(latestDeleteAt);
|
||||||
file = [[dir stringByAppendingPathComponent:
|
limit = ([when yearOfCommonEra] * 100 + [when monthOfYear]) * 100
|
||||||
[when descriptionWithCalendarFormat: @"%Y-%m-%d"]]
|
+ [when dayOfMonth];
|
||||||
stringByStandardizingPath];
|
|
||||||
if ([mgr fileExistsAtPath: file])
|
enumerator = [mgr enumeratorAtPath: dir];
|
||||||
|
while ((file = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
[mgr removeFileAtPath: file handler: nil];
|
if ([file length] == 10)
|
||||||
}
|
{
|
||||||
ti += day;
|
const char *s = [file UTF8String];
|
||||||
[pool release];
|
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;
|
if (YES == deb) debUndeleted = undeleted;
|
||||||
else logUndeleted = ti;
|
else logUndeleted = undeleted;
|
||||||
|
|
||||||
if (uncompressed < undeleted)
|
if (uncompressed < undeleted)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue