@@ -230,36 +230,15 @@ export class Cache extends EventEmitter {
230
230
this . activeLayer = ( async ( ) => {
231
231
const execAsync = promisify ( exec ) ;
232
232
233
- if ( this . externalLayersPath ) {
234
- // Check git for an uncommitted layer database file in external layers path
235
- try {
236
- const { stdout : revParseStdout } = await execAsync ( 'git rev-parse --show-toplevel' , { cwd : this . externalLayersPath } ) ;
237
- const gitRoot = revParseStdout . trim ( ) ;
238
- const relativePath = path . relative ( gitRoot , this . externalLayersPath ) ;
239
- const { stdout : statusStdout } = await execAsync ( `git status -z ${ relativePath } /*` , { cwd : gitRoot } ) ;
240
- if ( statusStdout !== '' ) {
241
- const layerDatabaseEntries = statusStdout . split ( '\0' ) . filter ( entry => entry . endsWith ( '.sqlite' ) ) ;
242
- if ( layerDatabaseEntries . length > 0 ) {
243
- const regex = / ( [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } ) \. s q l i t e $ / ;
244
- const match = layerDatabaseEntries [ 0 ] . match ( regex ) ;
245
- if ( match && this . layers . has ( match [ 1 ] ) ) {
246
- return this . layers . get ( match [ 1 ] ) ! ;
247
- }
248
- }
249
- }
250
- } catch ( error ) {
251
- // If git operations fail for external path, continue to create new layer
252
- }
253
-
254
- // Create a new layer database in external path
255
- const uuid = generateUuid ( ) ;
256
- const activeLayer = new Keyv ( new KeyvSqlite ( path . join ( this . externalLayersPath , `${ uuid } .sqlite` ) ) ) ;
257
- this . layers . set ( uuid , activeLayer ) ;
258
- return activeLayer ;
259
- } else {
260
- // Check git for an uncommitted layer database file in default path
261
- const { stdout : revParseStdout } = await execAsync ( 'git rev-parse --show-toplevel' ) ;
262
- const { stdout : statusStdout } = await execAsync ( 'git status -z test/simulation/cache/layers/*' , { cwd : revParseStdout . trim ( ) } ) ;
233
+ const targetPath = this . externalLayersPath || this . layersPath ;
234
+ const gitStatusPath = this . externalLayersPath
235
+ ? `${ path . relative ( await this . _getGitRoot ( targetPath ) , targetPath ) } /*`
236
+ : 'test/simulation/cache/layers/*' ;
237
+
238
+ // Check git for an uncommitted layer database file
239
+ try {
240
+ const gitRoot = await this . _getGitRoot ( targetPath ) ;
241
+ const { stdout : statusStdout } = await execAsync ( `git status -z ${ gitStatusPath } ` , { cwd : gitRoot } ) ;
263
242
if ( statusStdout !== '' ) {
264
243
const layerDatabaseEntries = statusStdout . split ( '\0' ) . filter ( entry => entry . endsWith ( '.sqlite' ) ) ;
265
244
if ( layerDatabaseEntries . length > 0 ) {
@@ -270,19 +249,27 @@ export class Cache extends EventEmitter {
270
249
}
271
250
}
272
251
}
273
-
274
- // Create a new layer database in default path
275
- const uuid = generateUuid ( ) ;
276
- const activeLayer = new Keyv ( new KeyvSqlite ( path . join ( this . layersPath , `${ uuid } .sqlite` ) ) ) ;
277
- this . layers . set ( uuid , activeLayer ) ;
278
- return activeLayer ;
252
+ } catch ( error ) {
253
+ // If git operations fail, continue to create new layer
279
254
}
255
+
256
+ // Create a new layer database
257
+ const uuid = generateUuid ( ) ;
258
+ const activeLayer = new Keyv ( new KeyvSqlite ( path . join ( targetPath , `${ uuid } .sqlite` ) ) ) ;
259
+ this . layers . set ( uuid , activeLayer ) ;
260
+ return activeLayer ;
280
261
} ) ( ) ;
281
262
}
282
263
283
264
return this . activeLayer ;
284
265
}
285
266
267
+ private async _getGitRoot ( cwd : string ) : Promise < string > {
268
+ const execAsync = promisify ( exec ) ;
269
+ const { stdout } = await execAsync ( 'git rev-parse --show-toplevel' , { cwd } ) ;
270
+ return stdout . trim ( ) ;
271
+ }
272
+
286
273
private async _compress ( value : string ) : Promise < string > {
287
274
const buffer = await compress ( value , { params : { [ zlib . constants . BROTLI_PARAM_QUALITY ] : 6 , } } ) ;
288
275
return buffer . toString ( 'base64' ) ;
0 commit comments