1
0
Fork 0
pull/1237/head
Sampark Sharma 2022-11-29 12:16:17 +00:00 committed by GitHub
parent 34f0143be2
commit 2e5a517460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 24 deletions

View File

@ -73,8 +73,7 @@ test('zstd extract tar', async () => {
'--use-compress-program', '--use-compress-program',
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
]) ])
.join(' '), .join(' ')
{cwd: undefined}
) )
}) })
@ -106,8 +105,7 @@ test('zstd extract tar with windows BSDtar', async () => {
'-P', '-P',
'-C', '-C',
workspace?.replace(/\\/g, '/') workspace?.replace(/\\/g, '/')
].join(' '), ].join(' ')
{cwd: undefined}
) )
} }
}) })
@ -137,8 +135,7 @@ test('gzip extract tar', async () => {
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']) .concat(['-z'])
.join(' '), .join(' ')
{cwd: undefined}
) )
}) })
@ -165,8 +162,7 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
workspace?.replace(/\\/g, '/'), workspace?.replace(/\\/g, '/'),
'--force-local', '--force-local',
'-z' '-z'
].join(' '), ].join(' ')
{cwd: undefined}
) )
} }
}) })
@ -206,6 +202,7 @@ test('zstd create tar', async () => {
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30' IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
]) ])
.join(' '), .join(' '),
undefined, // args
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -252,6 +249,7 @@ test('zstd create tar with windows BSDtar', async () => {
CacheFilename.Zstd.replace(/\\/g, '/'), CacheFilename.Zstd.replace(/\\/g, '/'),
TarFilename.replace(/\\/g, '/') TarFilename.replace(/\\/g, '/')
].join(' '), ].join(' '),
undefined, // args
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -274,8 +272,8 @@ test('gzip create tar', async () => {
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`,
[ [
`"${tarPath}"`,
'--posix', '--posix',
'-cf', '-cf',
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip, IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
@ -291,6 +289,7 @@ test('gzip create tar', async () => {
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']) .concat(['-z'])
.join(' '), .join(' '),
undefined, // args
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -309,15 +308,19 @@ test('zstd list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] [
`"${tarPath}"`,
'-tf',
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
'-P'
]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat([ .concat([
'--use-compress-program', '--use-compress-program',
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
]) ])
.join(' '), .join(' ')
{cwd: undefined}
) )
}) })
@ -343,8 +346,7 @@ test('zstd list tar with windows BSDtar', async () => {
'-tf', '-tf',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P' '-P'
].join(' '), ].join(' ')
{cwd: undefined}
) )
} }
}) })
@ -361,12 +363,16 @@ test('zstdWithoutLong list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] [
`"${tarPath}"`,
'-tf',
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
'-P'
]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']) .concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd'])
.join(' '), .join(' ')
{cwd: undefined}
) )
}) })
@ -381,11 +387,15 @@ test('gzip list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] [
`"${tarPath}"`,
'-tf',
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
'-P'
]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']) .concat(['-z'])
.join(' '), .join(' ')
{cwd: undefined}
) )
}) })

View File

@ -56,7 +56,7 @@ async function getTarArgs(
type: string, type: string,
archivePath = '' archivePath = ''
): Promise<string[]> { ): Promise<string[]> {
const args = [tarPath.path] const args = [`"${tarPath.path}"`]
const cacheFileName = utils.getCacheFileName(compressionMethod) const cacheFileName = utils.getCacheFileName(compressionMethod)
const tarFile = 'cache.tar' const tarFile = 'cache.tar'
const workingDirectory = getWorkingDirectory() const workingDirectory = getWorkingDirectory()
@ -260,11 +260,10 @@ export async function createTar(
compressionMethod: CompressionMethod compressionMethod: CompressionMethod
): Promise<void> { ): Promise<void> {
// Write source directories to manifest.txt to avoid command length limits // Write source directories to manifest.txt to avoid command length limits
const manifestFilename = 'manifest.txt'
writeFileSync( writeFileSync(
path.join(archiveFolder, manifestFilename), path.join(archiveFolder, ManifestFilename),
sourceDirectories.join('\n') sourceDirectories.join('\n')
) )
const args = await getArgs(compressionMethod, 'create') const args = await getArgs(compressionMethod, 'create')
await exec(args) await exec(args, undefined, {cwd: archiveFolder})
} }