forBuild method
The directory buildId's files are kept in, created, with every other
build's removed: a deploy starts with nothing of the last one.
Implementation
Directory? forBuild(String buildId) {
final String? root = directory;
if (root == null) return null;
final Directory mine = Directory('$root${Platform.pathSeparator}$buildId');
if (_prepared.add(mine.path)) {
try {
mine.createSync(recursive: true);
for (final FileSystemEntity other in Directory(root).listSync()) {
if (other.path != mine.path) other.deleteSync(recursive: true);
}
} on FileSystemException {
// A cache that cannot be written is a slower server, not a broken one.
}
}
return mine;
}