Skip to content

Commit 8e8ae5a

Browse files
committed
WIP
1 parent af05294 commit 8e8ae5a

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/LayerCache.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as cache from '@actions/cache'
55
import { ExecOptions } from '@actions/exec/lib/interfaces'
66
import { promises as fs } from 'fs'
77
import { assertManifests, Manifest, Manifests } from './Tar'
8-
import { dirname } from 'path'
98

109
class LayerCache {
1110
repotag: string
@@ -61,24 +60,20 @@ class LayerCache {
6160
}
6261

6362
private async separateAllLayerCaches() {
64-
const layerTars = (await exec.exec(`find . -name layer.tar`, [], { cwd: this.getUnpackedTarDir()})).stdoutStr.split(`\n`)
65-
const moveLayer = async (layer: string) => {
66-
const from = `${this.getUnpackedTarDir()}/${layer}`
67-
const to = `${this.getLayerCachesDir()}/${layer}`
68-
core.debug(`Moving layer tar from ${from} to ${to}`)
69-
await fs.mkdir(`${dirname(to)}`, { recursive: true })
70-
await fs.rename(from, to)
71-
}
72-
await Promise.all(layerTars.map(moveLayer))
63+
await this.moveLayertars(this.getUnpackedTarDir(), this.getLayerCachesDir())
7364
}
7465

7566
private async joinAllLayerCaches() {
76-
const layerTars = (await exec.exec(`find . -name layer.tar`, [], { cwd: this.getLayerCachesDir()})).stdoutStr.split(`\n`)
67+
await this.moveLayertars(this.getLayerCachesDir(), this.getUnpackedTarDir())
68+
}
69+
70+
private async moveLayertars(fromDir: string, toDir: string) {
71+
const layerTars = (await exec.exec(`find . -name layer.tar`, [], { cwd: fromDir })).stdoutStr.split(`\n`)
7772
const moveLayer = async (layer: string) => {
78-
const from = `${this.getLayerCachesDir()}/${layer}`
79-
const to = `${this.getUnpackedTarDir()}/${layer}`
73+
const from = `${fromDir}/${layer}`
74+
const to = `${toDir}/${layer}`
8075
core.debug(`Moving layer tar from ${from} to ${to}`)
81-
await fs.mkdir(`${dirname(to)}`, { recursive: true })
76+
await fs.mkdir(`${path.dirname(to)}`, { recursive: true })
8277
await fs.rename(from, to)
8378
}
8479
await Promise.all(layerTars.map(moveLayer))

0 commit comments

Comments
 (0)