Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid temporary file for downloads, fix CI.
  • Loading branch information
matanlurey committed Aug 29, 2023
commit aedc253416f0cc1d24331f5bcbfbbde4011c0470
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,23 @@ final class BuildBucketGoldenScraper {

/// Runs the scraper.
Future<int> run() async {
final io.File file;

// If the path is a URL, download it and store it in a temporary file.
final Uri? maybeUri = Uri.tryParse(pathOrUrl);
if (maybeUri == null) {
throw FormatException('Invalid path or URL: $pathOrUrl');
}

final String contents;
if (maybeUri.hasScheme) {
file = await _downloadFile(maybeUri);
contents = await _downloadFile(maybeUri);
} else {
file = io.File(pathOrUrl);
final io.File readFile = io.File(pathOrUrl);
if (!readFile.existsSync()) {
throw FormatException('File does not exist: $pathOrUrl');
}
contents = readFile.readAsStringSync();
}

// Read the file as a string.
final String contents = await file.readAsString();

// Check that it is a buildbucket log file.
if (!contents.contains(_buildBucketMagicString)) {
throw FormatException('Not a buildbucket log file: $pathOrUrl');
Expand Down Expand Up @@ -168,15 +169,14 @@ final class BuildBucketGoldenScraper {
static const String _buildBucketMagicString = '/b/s/w/ir/cache/builder/src/';
static const String _base64MagicString = 'See also the base64 encoded $_buildBucketMagicString';

static Future<io.File> _downloadFile(Uri uri) async {
final io.Directory tempDir = io.Directory.systemTemp.createTempSync('build_bucket_golden_scraper');
final io.File file = io.File(p.join(tempDir.path, uri.pathSegments.last));
static Future<String> _downloadFile(Uri uri) async {
final io.HttpClient client = io.HttpClient();
final io.HttpClientRequest request = await client.getUrl(uri);
final io.HttpClientResponse response = await request.close();
await response.pipe(file.openWrite());
final StringBuffer contents = StringBuffer();
await response.transform(utf8.decoder).forEach(contents.write);
client.close();
return file;
return contents.toString();
}
}

Expand Down
1 change: 1 addition & 0 deletions tools/pub_get_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
os.path.join(ENGINE_DIR, "testing", "symbols"),
os.path.join(ENGINE_DIR, "tools", "api_check"),
os.path.join(ENGINE_DIR, "tools", "android_lint"),
os.path.join(ENGINE_DIR, "tools", "build_bucket_golden_scraper"),
os.path.join(ENGINE_DIR, "tools", "clang_tidy"),
os.path.join(ENGINE_DIR, "tools", "const_finder"),
os.path.join(ENGINE_DIR, "tools", "pkg", "engine_repo_tools"),
Expand Down