Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
fileName
);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
core.debug(error);
throw `Failed to download version ${version}: ${error}`;
}
// Extract
let extPath: string | null = null;
if (osPlat == "win32") {
extPath = await tc.extractZip(downloadPath);
} else {
extPath = await tc.extractTar(downloadPath);
}
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
return await tc.cacheDir(extPath, "arduino-cli", version);
}
async function extractFiles(
file: string,
fileEnding: string,
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);
}
}
const hugoPath: string = path.join(baseLocation, 'hugobin');
await io.mkdirP(hugoPath);
core.addPath(hugoPath);
// Download and extract Hugo binary
await io.mkdirP(tempDir);
const hugoAssets: string = await tc.downloadTool(hugoURL);
let hugoBin: string = '';
if (osName === 'Windows') {
const hugoExtractedFolder: string = await tc.extractZip(
hugoAssets,
tempDir
);
hugoBin = `${hugoExtractedFolder}/hugo.exe`;
} else {
const hugoExtractedFolder: string = await tc.extractTar(
hugoAssets,
tempDir
);
hugoBin = `${hugoExtractedFolder}/hugo`;
}
await io.mv(hugoBin, hugoPath);
} catch (error) {
core.setFailed(error.message);
}
}
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);
}
} else if (process.platform == "darwin") {
type = "tarxz";
url = `http://downloads.dlang.org/releases/2.x/${dmdVersion}/dmd.${dmdVersion}.osx.tar.xz`;
}
}
}
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;
}