fix(cache): isolate Windows BSD tar temporary files

Run Windows BSD tar/zstd extraction and listing in private temporary
directories. Concurrent operations previously overwrote cache.tar in the
process working directory and could extract the wrong archive without
reporting an error. Debug listings during cache saves have the same race.

Resolve and quote archive and workspace paths before changing the child
working directory, and remove scratch files on success and failure.
Leave GNU tar, gzip, and the cache archive format unchanged.

Add deterministic regression tests for concurrent reads, relative paths
with spaces, and cleanup after failures in either subprocess.
This commit is contained in:
qmuntal committed 2026-09-17 15:27:15 +02:00
1 parent 8d05a01e45
commit da266fa6fd
3 files changed
+278 -32

No files matched your search

+12 -8
View File
@@ -88,6 +88,8 @@ test('zstd extract tar with windows BSDtar', async () => {
if (IS_WINDOWS) {
const mkdirMock = jest.spyOn(io, 'mkdirP')
const execMock = jest.spyOn(exec, 'exec')
const tempDirectory = getTempDir()
jest.spyOn(utils, 'createTempDirectory').mockResolvedValue(tempDirectory)
jest
.spyOn(utils, 'getGnuTarPathOnWindows')
.mockReturnValue(Promise.resolve(''))
@@ -106,11 +108,11 @@ test('zstd extract tar with windows BSDtar', async () => {
[
'zstd -d --long=30 --force -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
`"${archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')}"`
].join(' '),
undefined,
{
cwd: undefined,
cwd: tempDirectory,
env: expect.objectContaining(defaultEnv)
}
)
@@ -123,11 +125,11 @@ test('zstd extract tar with windows BSDtar', async () => {
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
'-C',
workspace?.replace(/\\/g, '/')
`"${workspace?.replace(/\\/g, '/')}"`
].join(' '),
undefined,
{
cwd: undefined,
cwd: tempDirectory,
env: expect.objectContaining(defaultEnv)
}
)
@@ -278,7 +280,7 @@ test('zstd create tar with windows BSDtar', async () => {
TarFilename.replace(/\\/g, '/'),
'-P',
'-C',
workspace?.replace(/\\/g, '/'),
`"${workspace?.replace(/\\/g, '/')}"`,
'--files-from',
ManifestFilename
].join(' '),
@@ -381,6 +383,8 @@ test('zstd list tar', async () => {
test('zstd list tar with windows BSDtar', async () => {
if (IS_WINDOWS) {
const execMock = jest.spyOn(exec, 'exec')
const tempDirectory = getTempDir()
jest.spyOn(utils, 'createTempDirectory').mockResolvedValue(tempDirectory)
jest
.spyOn(utils, 'getGnuTarPathOnWindows')
.mockReturnValue(Promise.resolve(''))
@@ -396,11 +400,11 @@ test('zstd list tar with windows BSDtar', async () => {
[
'zstd -d --long=30 --force -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
`"${archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')}"`
].join(' '),
undefined,
{
cwd: undefined,
cwd: tempDirectory,
env: expect.objectContaining(defaultEnv)
}
)
@@ -415,7 +419,7 @@ test('zstd list tar with windows BSDtar', async () => {
].join(' '),
undefined,
{
cwd: undefined,
cwd: tempDirectory,
env: expect.objectContaining(defaultEnv)
}
)