pruneStaleTestStorageDirectories static method
void
pruneStaleTestStorageDirectories({})
Removes runner-owned temporary directories left by a process terminated before suite teardown. Normal runs remove their own storage and artifact transport directories; the age threshold protects active concurrent runs.
Implementation
@visibleForTesting
static void pruneStaleTestStorageDirectories({
Directory? temporaryRoot,
DateTime? now,
Duration staleAfter = const Duration(days: 1),
}) {
if (_staleStoragePruned && temporaryRoot == null) return;
final root = temporaryRoot ?? Directory.systemTemp;
final cutoff = (now ?? DateTime.now()).subtract(staleAfter);
try {
for (final entity in root.listSync(followLinks: false)) {
if (entity is! Directory || !_isRunnerTemporaryDirectory(entity)) {
continue;
}
try {
if (entity.statSync().modified.isBefore(cutoff)) {
entity.deleteSync(recursive: true);
}
} on FileSystemException {
// A concurrent cleanup or filesystem error must not block setup.
}
}
if (temporaryRoot == null) _staleStoragePruned = true;
} on FileSystemException {
// Temp cleanup is best effort; the current suite still owns its directory.
}
}