1
0
Fork 0

Limit files extracted by restoreCache to those in paths option.

pull/1927/head
Sam Pinkus 2025-01-08 18:33:22 +10:00
parent adb9c4a7f4
commit 08ea137a02
4 changed files with 19 additions and 14 deletions

View File

@ -154,7 +154,7 @@ test('restore with gzip compressed cache found', async () => {
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath) expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)
expect(unlinkFileMock).toHaveBeenCalledTimes(1) expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath) expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@ -215,7 +215,7 @@ test('restore with zstd compressed cache found', async () => {
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`) expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)
expect(getCompressionMock).toHaveBeenCalledTimes(1) expect(getCompressionMock).toHaveBeenCalledTimes(1)
}) })
@ -273,7 +273,7 @@ test('restore with cache found for restore key', async () => {
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`) expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)
expect(getCompressionMock).toHaveBeenCalledTimes(1) expect(getCompressionMock).toHaveBeenCalledTimes(1)
}) })

View File

@ -203,7 +203,7 @@ test('restore with gzip compressed cache found', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)
expect(unlinkFileMock).toHaveBeenCalledTimes(1) expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath) expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@ -279,7 +279,7 @@ test('restore with zstd compressed cache found', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)
expect(unlinkFileMock).toHaveBeenCalledTimes(1) expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath) expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@ -356,7 +356,7 @@ test('restore with cache found for restore key', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)
expect(extractTarMock).toHaveBeenCalledTimes(1) expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod) expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)
expect(unlinkFileMock).toHaveBeenCalledTimes(1) expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath) expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)

View File

@ -177,7 +177,7 @@ async function restoreCacheV1(
)} MB (${archiveFileSize} B)` )} MB (${archiveFileSize} B)`
) )
await extractTar(archivePath, compressionMethod) await extractTar(archivePath, compressionMethod, paths)
core.info('Cache restored successfully') core.info('Cache restored successfully')
return cacheEntry.cacheKey return cacheEntry.cacheKey
@ -291,7 +291,7 @@ async function restoreCacheV2(
await listTar(archivePath, compressionMethod) await listTar(archivePath, compressionMethod)
} }
await extractTar(archivePath, compressionMethod) await extractTar(archivePath, compressionMethod, paths)
core.info('Cache restored successfully') core.info('Cache restored successfully')
return response.matchedKey return response.matchedKey

View File

@ -55,7 +55,8 @@ async function getTarArgs(
tarPath: ArchiveTool, tarPath: ArchiveTool,
compressionMethod: CompressionMethod, compressionMethod: CompressionMethod,
type: string, type: string,
archivePath = '' archivePath = '',
paths: string[] = [],
): Promise<string[]> { ): Promise<string[]> {
const args = [`"${tarPath.path}"`] const args = [`"${tarPath.path}"`]
const cacheFileName = utils.getCacheFileName(compressionMethod) const cacheFileName = utils.getCacheFileName(compressionMethod)
@ -95,7 +96,8 @@ async function getTarArgs(
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), : archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P', '-P',
'-C', '-C',
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/') workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
...paths,
) )
break break
case 'list': case 'list':
@ -128,7 +130,8 @@ async function getTarArgs(
async function getCommands( async function getCommands(
compressionMethod: CompressionMethod, compressionMethod: CompressionMethod,
type: string, type: string,
archivePath = '' archivePath = '',
paths: string[] = [],
): Promise<string[]> { ): Promise<string[]> {
let args let args
@ -137,7 +140,8 @@ async function getCommands(
tarPath, tarPath,
compressionMethod, compressionMethod,
type, type,
archivePath archivePath,
paths,
) )
const compressionArgs = const compressionArgs =
type !== 'create' type !== 'create'
@ -272,12 +276,13 @@ export async function listTar(
// Extract a tar // Extract a tar
export async function extractTar( export async function extractTar(
archivePath: string, archivePath: string,
compressionMethod: CompressionMethod compressionMethod: CompressionMethod,
paths?: string[],
): Promise<void> { ): Promise<void> {
// Create directory to extract tar into // Create directory to extract tar into
const workingDirectory = getWorkingDirectory() const workingDirectory = getWorkingDirectory()
await io.mkdirP(workingDirectory) await io.mkdirP(workingDirectory)
const commands = await getCommands(compressionMethod, 'extract', archivePath) const commands = await getCommands(compressionMethod, 'extract', archivePath, paths)
await execCommands(commands) await execCommands(commands)
} }