Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
destinationFolder: string
): Promise {
const stats = fs.statSync(file);
if (!stats) {
throw new Error(`Failed to extract ${file} - it doesn't exist`);
} else if (stats.isDirectory()) {
throw new Error(`Failed to extract ${file} - it is a directory`);
}
if ('.tgz' === fileEnding) {
await tc.extractTar(file, destinationFolder);
} else if ('.zip' === fileEnding) {
await tc.extractZip(file, destinationFolder);
} else {
// fall through and use sevenZip
await tc.extract7z(file, destinationFolder);
}
}
downloadPath = await tc.downloadTool(downloadUrl);
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return await acquireNodeFromFallbackLocation(version);
}
throw err;
}
//
// Extract
//
let extPath: string;
if (osPlat == 'win32') {
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
} else {
extPath = await tc.extractTar(downloadPath);
}
//
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
let toolRoot = path.join(extPath, fileName);
return await tc.cacheDir(toolRoot, 'node', version);
}
async function extract(format: string, archive: string, into?: string) {
if (format.endsWith(".7z"))
return await tc.extract7z(archive, into);
else if (format.endsWith(".zip"))
return await tc.extractZip(archive, into);
else if (/\.tar(\.\w+)?$/.test(format))
return await tc.extractTar(archive, into, 'x');
throw new Error("unsupported archive format: " + format);
}
}
}
}
if (!url.length || type === undefined)
throw new Error(`Failed to determine dmd download URL for version ${dmdVersion}`);
core.debug("Downloading DMD from " + url);
const tmppath = await tc.downloadTool(url);
let dstdir: string;
switch (type) {
case "tarxz":
dstdir = await tc.extractTar(tmppath);
break;
case "7z":
dstdir = await tc.extract7z(tmppath);
break;
case "zip":
dstdir = await tc.extractZip(tmppath);
break;
default: throw new Error("unexpected program state");
}
if (dmdVersion !== "master")
tc.cacheDir(dstdir, "dmd", dmdVersion);
return dstdir;
}
export async function downloadAndExtractTool(url: string): Promise {
const downloadPath = await toolCache.downloadTool(url);
let extractedPath: string;
if (url.indexOf('.zip') != -1) {
extractedPath = await toolCache.extractZip(downloadPath);
} else if (url.indexOf('.tar.gz') != -1) {
extractedPath = await toolCache.extractTar(downloadPath);
} else if (url.indexOf('.7z') != -1) {
extractedPath = await toolCache.extract7z(downloadPath);
} else {
throw new Error(
`Unexpected download archive type, downloadPath: ${downloadPath}`,
);
}
return extractedPath;
}