Improve clean up if extraction fails
This commit is contained in:
parent
3da852e107
commit
28db28fc03
9 changed files with 128 additions and 102 deletions
44
lib/tar.js
generated
44
lib/tar.js
generated
|
|
@ -98,7 +98,7 @@ async function isZstdAvailable(logger) {
|
|||
return { available: false };
|
||||
}
|
||||
}
|
||||
async function extract(tarPath, compressionMethod, tarVersion) {
|
||||
async function extract(tarPath, compressionMethod, tarVersion, logger) {
|
||||
switch (compressionMethod) {
|
||||
case "gzip":
|
||||
// Defensively continue to call the toolcache API as requesting a gzipped
|
||||
|
|
@ -108,7 +108,7 @@ async function extract(tarPath, compressionMethod, tarVersion) {
|
|||
if (!tarVersion) {
|
||||
throw new Error("Could not determine tar version, which is required to extract a Zstandard archive.");
|
||||
}
|
||||
return await extractTarZst(tarPath, tarVersion);
|
||||
return await extractTarZst(tarPath, tarVersion, logger);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -118,30 +118,36 @@ async function extract(tarPath, compressionMethod, tarVersion) {
|
|||
* @param dest destination directory. Optional.
|
||||
* @returns path to the destination directory
|
||||
*/
|
||||
async function extractTarZst(file, tarVersion) {
|
||||
async function extractTarZst(file, tarVersion, logger) {
|
||||
if (!file) {
|
||||
throw new Error("parameter 'file' is required");
|
||||
}
|
||||
// Create dest
|
||||
const dest = await createExtractFolder();
|
||||
// Initialize args
|
||||
const args = ["-x", "-v"];
|
||||
let destArg = dest;
|
||||
let fileArg = file;
|
||||
if (process.platform === "win32" && tarVersion.type === "gnu") {
|
||||
args.push("--force-local");
|
||||
destArg = dest.replace(/\\/g, "/");
|
||||
// Technically only the dest needs to have `/` but for aesthetic consistency
|
||||
// convert slashes in the file arg too.
|
||||
fileArg = file.replace(/\\/g, "/");
|
||||
try {
|
||||
// Initialize args
|
||||
const args = ["-x", "-v"];
|
||||
let destArg = dest;
|
||||
let fileArg = file;
|
||||
if (process.platform === "win32" && tarVersion.type === "gnu") {
|
||||
args.push("--force-local");
|
||||
destArg = dest.replace(/\\/g, "/");
|
||||
// Technically only the dest needs to have `/` but for aesthetic consistency
|
||||
// convert slashes in the file arg too.
|
||||
fileArg = file.replace(/\\/g, "/");
|
||||
}
|
||||
if (tarVersion.type === "gnu") {
|
||||
// Suppress warnings when using GNU tar to extract archives created by BSD tar
|
||||
args.push("--warning=no-unknown-keyword");
|
||||
args.push("--overwrite");
|
||||
}
|
||||
args.push("-C", destArg, "-f", fileArg);
|
||||
await (0, actions_util_1.runTool)(`tar`, args);
|
||||
}
|
||||
if (tarVersion.type === "gnu") {
|
||||
// Suppress warnings when using GNU tar to extract archives created by BSD tar
|
||||
args.push("--warning=no-unknown-keyword");
|
||||
args.push("--overwrite");
|
||||
catch (e) {
|
||||
await (0, util_1.cleanUpGlob)(dest, "extraction destination directory", logger);
|
||||
throw e;
|
||||
}
|
||||
args.push("-C", destArg, "-f", fileArg);
|
||||
await (0, actions_util_1.runTool)(`tar`, args);
|
||||
return dest;
|
||||
}
|
||||
async function createExtractFolder() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue