@@ -4,9 +4,11 @@ import { Logger } from "common/logger";
44import { PackageState , ProgressInfo , Store } from "common/types" ;
55import { MinimalContext } from "main/context" ;
66import spawn from "main/os/spawn" ;
7+ import { execFile } from "child_process" ;
78import { dirname , join } from "path" ;
89import querystring from "querystring" ;
910import * as semver from "semver" ;
11+ import { promisify } from "util" ;
1012import which from "which" ;
1113import { downloadToFileWithRetry } from "main/net/download" ;
1214import { request } from "main/net/request/metal-request" ;
@@ -17,6 +19,7 @@ import formulas, { FormulaSpec } from "main/broth/formulas";
1719import { platformString } from "main/broth/platform" ;
1820import { unzip } from "main/broth/unzip" ;
1921
22+ const execFileAsync = promisify ( execFile ) ;
2023const sanityCheckTimeout = 10000 ;
2124const platform = platformString ( ) ;
2225
@@ -450,11 +453,42 @@ export class Package implements PackageLike {
450453 return presentVersions ;
451454 }
452455
456+ private async isBinaryNativeArch (
457+ logger : Logger ,
458+ versionPrefix : string
459+ ) : Promise < boolean > {
460+ if ( process . platform !== "darwin" || process . arch !== "arm64" ) {
461+ return true ;
462+ }
463+
464+ const binaryPath = join ( versionPrefix , this . name ) ;
465+ try {
466+ const { stdout } = await execFileAsync ( "/usr/bin/file" , [ binaryPath ] ) ;
467+ logger . debug ( `Architecture check for ${ this . name } : ${ stdout . trim ( ) } ` ) ;
468+
469+ if ( ! stdout . includes ( "arm64" ) ) {
470+ logger . info (
471+ `${ this . name } binary is not arm64-native, will re-download`
472+ ) ;
473+ return false ;
474+ }
475+ return true ;
476+ } catch ( e ) {
477+ logger . warn ( `Could not check architecture of ${ this . name } : ${ e . message } ` ) ;
478+ return true ;
479+ }
480+ }
481+
453482 async isVersionValid ( logger : Logger , v : Version ) : Promise < boolean > {
454483 const ctx = new MinimalContext ( ) ;
455484 const { formula } = this ;
456485 const { sanityCheck } = formula ;
457486 const versionPrefix = this . getVersionPrefix ( v ) ;
487+
488+ if ( ! ( await this . isBinaryNativeArch ( logger , versionPrefix ) ) ) {
489+ return false ;
490+ }
491+
458492 try {
459493 let t1 = Date . now ( ) ;
460494 await Promise . race ( [
0 commit comments