@@ -1306,43 +1306,33 @@ def fetch
1306
1306
1307
1307
oh1 "Fetching #{ Formatter . identifier ( formula . full_name ) } " . strip
1308
1308
1309
- if pour_bottle? ( output_warning : true )
1309
+ downloadable_object = downloadable
1310
+ check_attestation = if pour_bottle? ( output_warning : true )
1310
1311
fetch_bottle_tab
1312
+
1313
+ !downloadable_object . cached_download . exist?
1311
1314
else
1312
1315
@formula = Homebrew ::API ::Formula . source_download ( formula ) if formula . loaded_from_api?
1313
1316
1314
1317
formula . fetch_patches
1315
1318
formula . resources . each ( &:fetch )
1316
- end
1317
- downloadable . fetch
1318
-
1319
- self . class . fetched << formula
1320
- end
1321
1319
1322
- sig { returns ( Downloadable ) }
1323
- def downloadable
1324
- if ( bottle_path = formula . local_bottle_path )
1325
- Resource ::Local . new ( bottle_path )
1326
- elsif pour_bottle?
1327
- T . must ( formula . bottle )
1328
- else
1329
- T . must ( formula . resource )
1320
+ false
1330
1321
end
1331
- end
1322
+ downloadable_object . fetch
1332
1323
1333
- sig { void }
1334
- def pour
1335
1324
# We skip `gh` to avoid a bootstrapping cycle, in the off-chance a user attempts
1336
1325
# to explicitly `brew install gh` without already having a version for bootstrapping.
1337
1326
# We also skip bottle installs from local bottle paths, as these are done in CI
1338
1327
# as part of the build lifecycle before attestations are produced.
1339
- if Homebrew ::Attestation . enabled? &&
1328
+ if check_attestation &&
1329
+ Homebrew ::Attestation . enabled? &&
1340
1330
formula . tap &.core_tap? &&
1341
1331
formula . name != "gh" &&
1342
1332
formula . local_bottle_path . blank?
1343
1333
ohai "Verifying attestation for #{ formula . name } "
1344
1334
begin
1345
- Homebrew ::Attestation . check_core_attestation T . must ( formula . bottle )
1335
+ Homebrew ::Attestation . check_core_attestation T . cast ( downloadable_object , Bottle )
1346
1336
rescue Homebrew ::Attestation ::GhIncompatible
1347
1337
# A small but significant number of users have developer mode enabled
1348
1338
# but *also* haven't upgraded in a long time, meaning that their `gh`
@@ -1399,6 +1389,30 @@ def pour
1399
1389
end
1400
1390
end
1401
1391
1392
+ self . class . fetched << formula
1393
+ rescue CannotInstallFormulaError
1394
+ if downloadable_object &&
1395
+ downloadable_object . respond_to? ( :cached_download ) &&
1396
+ downloadable_object . cached_download . exist?
1397
+ downloadable_object . cached_download . unlink
1398
+ end
1399
+
1400
+ raise
1401
+ end
1402
+
1403
+ sig { returns ( Downloadable ) }
1404
+ def downloadable
1405
+ if ( bottle_path = formula . local_bottle_path )
1406
+ Resource ::Local . new ( bottle_path )
1407
+ elsif pour_bottle?
1408
+ T . must ( formula . bottle )
1409
+ else
1410
+ T . must ( formula . resource )
1411
+ end
1412
+ end
1413
+
1414
+ sig { void }
1415
+ def pour
1402
1416
HOMEBREW_CELLAR . cd do
1403
1417
downloadable . downloader . stage
1404
1418
end
0 commit comments