Skip to content

Commit d0e6cca

Browse files
authored
Mitigate out of free space issues while running dartdoc postprocessing. (#8079)
1 parent b940213 commit d0e6cca

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

pkg/pub_worker/lib/src/bin/dartdoc_wrapper.dart

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Future<void> postProcessDartdoc({
2424
required String docDir,
2525
}) async {
2626
_log.info('Running dartdoc post-processing');
27-
final tmpOutDir = p.join(outputFolder, '_doc');
28-
await Directory(tmpOutDir).create(recursive: true);
27+
final tmpOutDir = Directory(p.join(outputFolder, '_doc'));
28+
await tmpOutDir.create(recursive: true);
2929
final processingFuture = Isolate.run(() async {
3030
final files = Directory(docDir)
3131
.list(recursive: true, followLinks: false)
3232
.whereType<File>();
3333
await for (final file in files) {
3434
final suffix = file.path.substring(docDir.length + 1);
35-
final targetFile = File(p.join(tmpOutDir, suffix));
35+
final targetFile = File(p.join(tmpOutDir.path, suffix));
3636
await targetFile.parent.create(recursive: true);
3737
final isDartDocSidebar =
3838
file.path.endsWith('.html') && file.path.endsWith('-sidebar.html');
@@ -85,14 +85,34 @@ Future<void> postProcessDartdoc({
8585
_log.info('Finished .tar.gz archive');
8686
});
8787

88-
await Future.wait([
89-
processingFuture,
90-
archiveFuture,
91-
]);
88+
try {
89+
await Future.wait([
90+
processingFuture,
91+
archiveFuture,
92+
]);
9293

93-
// Move from temporary output directory to final one, ensuring that
94-
// documentation files won't be present unless all files have been processed.
95-
// This helps if there is a timeout along the way.
96-
await Directory(tmpOutDir).rename(p.join(outputFolder, 'doc'));
97-
await tmpTar.rename(p.join(outputFolder, 'doc', 'package.tar.gz'));
94+
// Move from temporary output directory to final one, ensuring that
95+
// documentation files won't be present unless all files have been processed.
96+
// This helps if there is a timeout along the way.
97+
await tmpOutDir.rename(p.join(outputFolder, 'doc'));
98+
await tmpTar.rename(p.join(outputFolder, 'doc', 'package.tar.gz'));
99+
} catch (e, st) {
100+
// We don't know what's wrong with the post-processing, and we treat
101+
// the output as incorrect. Deleting, so it won't be included in the blob.
102+
await tmpOutDir.deleteIgnoringErrors(recursive: true);
103+
await tmpTar.deleteIgnoringErrors();
104+
105+
_log.shout('Failed to run dartdoc post-processing.', e, st);
106+
rethrow;
107+
}
108+
}
109+
110+
extension on FileSystemEntity {
111+
Future<void> deleteIgnoringErrors({bool recursive = false}) async {
112+
try {
113+
await delete(recursive: recursive);
114+
} catch (_) {
115+
// ignored
116+
}
117+
}
98118
}

0 commit comments

Comments
 (0)