@@ -14,7 +14,7 @@ class LayerCache {
1414 ids : string [ ] = [ ]
1515 unformattedSaveKey : string = ''
1616 restoredRootKey : string = ''
17- imagesDir : string = path . resolve ( ` ${ __dirname } /../ .adlc` )
17+ imagesDir : string = path . join ( __dirname , '..' , ' .adlc' )
1818 enabledParallel = true
1919 concurrency : number = 4
2020
@@ -49,8 +49,8 @@ class LayerCache {
4949 }
5050
5151 private async saveImageAsUnpacked ( ) {
52- await fs . mkdir ( this . getSavedImageTarDir ( ) , { recursive : true } )
53- await this . exec ( `sh -c` , [ `docker save '${ ( await this . makeRepotagsDockerSaveArgReady ( this . ids ) ) . join ( `' '` ) } ' | tar xf - -C .` ] , { cwd : this . getSavedImageTarDir ( ) } )
52+ await fs . mkdir ( this . getUnpackedTarDir ( ) , { recursive : true } )
53+ await this . exec ( `sh -c` , [ `docker save '${ ( await this . makeRepotagsDockerSaveArgReady ( this . ids ) ) . join ( `' '` ) } ' | tar xf - -C .` ] , { cwd : this . getUnpackedTarDir ( ) } )
5454 }
5555
5656 private async makeRepotagsDockerSaveArgReady ( repotags : string [ ] ) : Promise < string [ ] > {
@@ -91,14 +91,14 @@ class LayerCache {
9191
9292 private async moveLayerTarsInDir ( fromDir : string , toDir : string ) {
9393 const layerTars = ( await recursiveReaddir ( fromDir ) )
94- . filter ( path => path . endsWith ( `/ layer.tar`) )
95- . map ( path => path . replace ( ` ${ fromDir } /` , `` ) )
94+ . filter ( layerPath => path . basename ( layerPath ) === ` layer.tar`)
95+ . map ( layerPath => path . relative ( fromDir , layerPath ) )
9696
9797 const moveLayer = async ( layer : string ) => {
98- const from = path . resolve ( ` ${ fromDir } / ${ layer } ` )
99- const to = path . resolve ( ` ${ toDir } / ${ layer } ` )
98+ const from = path . join ( fromDir , layer )
99+ const to = path . join ( toDir , layer )
100100 core . debug ( `Moving layer tar from ${ from } to ${ to } ` )
101- await fs . mkdir ( ` ${ path . dirname ( to ) } ` , { recursive : true } )
101+ await fs . mkdir ( path . dirname ( to ) , { recursive : true } )
102102 await fs . rename ( from , to )
103103 }
104104 await Promise . all ( layerTars . map ( moveLayer ) )
@@ -201,14 +201,14 @@ class LayerCache {
201201 }
202202
203203 private async restoreSingleLayerBy ( id : string ) : Promise < string > {
204- const path = this . genSingleLayerStorePath ( id )
204+ const layerPath = this . genSingleLayerStorePath ( id )
205205 const key = await this . recoverSingleLayerKey ( id )
206- const dir = path . replace ( / [ ^ / \\ ] + $ / , `` )
206+ const dir = path . dirname ( layerPath )
207207
208- core . debug ( JSON . stringify ( { log : `restoreSingleLayerBy` , id, path , dir, key } ) )
208+ core . debug ( JSON . stringify ( { log : `restoreSingleLayerBy` , id, layerPath , dir, key } ) )
209209
210210 await fs . mkdir ( dir , { recursive : true } )
211- const result = await cache . restoreCache ( [ path ] , key )
211+ const result = await cache . restoreCache ( [ layerPath ] , key )
212212
213213 if ( result == null ) {
214214 throw new Error ( `${ LayerCache . ERROR_LAYER_CACHE_NOT_FOUND_STR } : ${ JSON . stringify ( { id } ) } ` )
@@ -232,23 +232,19 @@ class LayerCache {
232232 }
233233
234234 getUnpackedTarDir ( ) : string {
235- return path . resolve ( ` ${ this . getImagesDir ( ) } / ${ this . getCurrentTarStoreDir ( ) } ` )
235+ return path . join ( this . getImagesDir ( ) , this . getCurrentTarStoreDir ( ) )
236236 }
237237
238238 getLayerCachesDir ( ) {
239239 return `${ this . getUnpackedTarDir ( ) } -layers`
240240 }
241241
242- getSavedImageTarDir ( ) : string {
243- return path . resolve ( `${ this . getImagesDir ( ) } /${ this . getCurrentTarStoreDir ( ) } ` )
244- }
245-
246242 getCurrentTarStoreDir ( ) : string {
247243 return 'image'
248244 }
249245
250246 genSingleLayerStorePath ( id : string ) {
251- return path . resolve ( ` ${ this . getLayerCachesDir ( ) } / ${ id } / layer.tar`)
247+ return path . join ( this . getLayerCachesDir ( ) , id , ` layer.tar`)
252248 }
253249
254250 async generateRootHashFromManifest ( ) : Promise < string > {
@@ -296,8 +292,7 @@ class LayerCache {
296292 }
297293
298294 async getLayerIds ( ) : Promise < string [ ] > {
299- const getIdfromLayerRelativePath = ( path : string ) => path . replace ( '/layer.tar' , '' )
300- const layerIds = ( await this . getLayerTarFiles ( ) ) . map ( getIdfromLayerRelativePath ) ;
295+ const layerIds = ( await this . getLayerTarFiles ( ) ) . map ( path . dirname ) ;
301296 core . debug ( JSON . stringify ( { log : `getLayerIds` , layerIds } ) )
302297 return layerIds
303298 }
0 commit comments