@@ -3,7 +3,6 @@ import * as path from 'path';
33import * as os from 'os' ;
44import { execFile } from 'child_process' ;
55import { promisify } from 'util' ;
6- import { createHash } from 'crypto' ;
76
87const execFileAsync = promisify ( execFile ) ;
98
@@ -132,7 +131,7 @@ async function getVersionFromSiteDir(siteDir: string): Promise<string | undefine
132131// Two cache dir formats:
133132// New (≥0.30.3): <hash16>-<pathhash16> (33 chars) — per binary path
134133// Old (≤0.30.2): <hash16> (16 chars) — per payload, shared
135- async function getJacVersionFromCache ( jacPath : string , hash16 : string | undefined ) : Promise < string | undefined > {
134+ async function getJacVersionFromCache ( hash16 : string | undefined ) : Promise < string | undefined > {
136135 const rtDir = path . join ( jacCacheBase ( ) , 'jac' , 'rt' ) ;
137136 let hashDirs : string [ ] ;
138137 try { hashDirs = await fs . readdir ( rtDir ) ; }
@@ -143,30 +142,16 @@ async function getJacVersionFromCache(jacPath: string, hash16: string | undefine
143142 const HEX16 = / ^ [ 0 - 9 a - f ] { 16 } $ / ;
144143 const newFormatDirs = hashDirs . filter ( d => d . length === RT_KEY_LEN && d [ 16 ] === '-' ) ;
145144
146- // 1. hash16 (payload identity) match — exact and path-independent
145+ // 1. hash16 (payload identity) match — rtKey() always derives the dir name from the
146+ // same trailer hash16, so any binary with a new-format dir has a readable hash16.
147147 if ( hash16 ) {
148148 for ( const dir of newFormatDirs . filter ( d => d . startsWith ( hash16 + '-' ) ) ) {
149149 const ver = await getVersionFromSiteDir ( path . join ( rtDir , dir , 'site' ) ) ;
150150 if ( ver ) return ver ;
151151 }
152152 }
153153
154- // 2. pathhash match — covers binaries whose trailer we couldn't read
155- let resolvedPath : string ;
156- try { resolvedPath = await fs . realpath ( jacPath ) ; } catch { resolvedPath = jacPath ; }
157-
158- const pathHashFor = ( p : string ) => createHash ( 'sha256' ) . update ( p ) . digest ( 'hex' ) . slice ( 0 , 16 ) ;
159-
160- let matchingDirs = newFormatDirs . filter ( d => d . slice ( 17 ) === pathHashFor ( resolvedPath ) ) ;
161- if ( matchingDirs . length === 0 && resolvedPath !== jacPath ) {
162- matchingDirs = newFormatDirs . filter ( d => d . slice ( 17 ) === pathHashFor ( jacPath ) ) ;
163- }
164- for ( const dir of matchingDirs ) {
165- const ver = await getVersionFromSiteDir ( path . join ( rtDir , dir , 'site' ) ) ;
166- if ( ver ) return ver ;
167- }
168-
169- // 3. Old format — only safe when no new-format dirs exist (avoids stale post-GC reads)
154+ // 2. Old format — only safe when no new-format dirs exist (avoids stale post-GC reads)
170155 const oldFormatDirs = hashDirs . filter ( d => d . length === 16 && HEX16 . test ( d ) ) ;
171156 if ( newFormatDirs . length === 0 && oldFormatDirs . length > 0 ) {
172157 const versions : string [ ] = [ ] ;
@@ -203,7 +188,7 @@ export async function getJacVersion(jacPath: string): Promise<string | undefined
203188 if ( memo [ hash16 ] ) return memo [ hash16 ] ;
204189 }
205190
206- const version = ( await getJacVersionFromCache ( jacPath , hash16 ) ) ?? ( await getJacVersionFromBinary ( jacPath ) ) ;
191+ const version = ( await getJacVersionFromCache ( hash16 ) ) ?? ( await getJacVersionFromBinary ( jacPath ) ) ;
207192 if ( version && hash16 ) await memoStore ( hash16 , version ) ;
208193 return version ;
209194}
0 commit comments