2023-07-17 00:58:16 +00:00
|
|
|
/**
|
|
|
|
* This standalone module is responsible for cleaning up the list of stored
|
|
|
|
* extracts, so only the recent ones remain. This is meant to be linked as a
|
|
|
|
* cron scheduled program.
|
|
|
|
*/
|
|
|
|
module cleaner;
|
|
|
|
|
|
|
|
import std.stdio;
|
|
|
|
import std.file;
|
|
|
|
import std.path;
|
|
|
|
import std.datetime;
|
|
|
|
|
|
|
|
const EXTRACTS_DIR = "extracts";
|
|
|
|
|
|
|
|
int main() {
|
2023-07-17 01:18:26 +00:00
|
|
|
if (!exists(EXTRACTS_DIR)) return 0;
|
2023-07-17 00:58:16 +00:00
|
|
|
immutable SysTime now = Clock.currTime();
|
|
|
|
foreach (DirEntry entry; dirEntries(EXTRACTS_DIR, SpanMode.shallow, false)) {
|
|
|
|
Duration age = now - entry.timeLastModified();
|
|
|
|
if (age.total!"days" > 5) {
|
|
|
|
writefln!"Removing directory %s because it's too old."(entry.name);
|
|
|
|
rmdirRecurse(entry.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|