Skip to content

Commit 9f3d238

Browse files
committed
fix: extract tar.xz files correctly with 7zip
1 parent b7e481e commit 9f3d238

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/utils/setup/extract.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { mkdirP } from "@actions/io"
1+
import { basename, dirname, join } from "path"
2+
import { mkdirP, mv } from "@actions/io"
23
import { grantUserWriteAccess } from "admina"
34
import { info, warning } from "ci-log"
45
import { execa } from "execa"
6+
import { rm } from "fs/promises"
57
import { installAptPack } from "setup-apt"
68
import which from "which"
79
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
@@ -66,9 +68,35 @@ let sevenZip: string | undefined
6668

6769
/// Extract 7z using 7z
6870
export async function extract7Zip(file: string, dest: string) {
71+
const name = basename(file)
72+
73+
if (/.*\.tar\..+$/.test(name)) {
74+
// if the file is tar.*, extract the compression first
75+
const tarDir = dirname(file)
76+
await run7zip(file, tarDir)
77+
// extract the tar
78+
const tarName = name.slice(0, -3)
79+
const tarFile = `${tarDir}/${tarName}`
80+
await run7zip(tarFile, tarDir)
81+
await rm(tarFile)
82+
// Move the extracted files to the destination
83+
const folderName = tarName.slice(0, -4)
84+
const folderPath = join(tarDir, folderName)
85+
await mkdirP(dirname(dest))
86+
info(`Moving ${folderName} to ${dest}`)
87+
await mv(folderPath, dest, { force: true })
88+
} else {
89+
// extract the 7z file directly
90+
await run7zip(file, dest)
91+
}
92+
93+
return dest
94+
}
95+
96+
async function run7zip(file: string, dest: string) {
97+
info(`7z: extracting ${file} to ${dest}`)
6998
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
7099
await grantUserWriteAccess(dest)
71-
return dest
72100
}
73101

74102
/// install 7z if needed

0 commit comments

Comments
 (0)