Skip to content

Commit

Permalink
fix: extract tar.xz files correctly with 7zip
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 30, 2025
1 parent b7e481e commit ff86c1b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions src/utils/setup/extract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mkdirP } from "@actions/io"
import { basename, dirname, join } from "path"
import { mkdirP, mv } from "@actions/io"
import { grantUserWriteAccess } from "admina"
import { info, warning } from "ci-log"
import { execa } from "execa"
import { rm } from "fs/promises"
import { installAptPack } from "setup-apt"
import which from "which"
import { setupSevenZip } from "../../sevenzip/sevenzip.js"
Expand Down Expand Up @@ -66,9 +68,33 @@ let sevenZip: string | undefined

/// Extract 7z using 7z
export async function extract7Zip(file: string, dest: string) {
const name = basename(file)

if (/.*\.tar\..+$/.test(name)) {
// if the file is tar.*, extract the compression first
const tarDir = dirname(file)
await run7zip(file, tarDir)
// extract the tar
const tarName = name.slice(0, -3)
const tarFile = `${tarDir}/${tarName}`
await run7zip(tarFile, tarDir)
await rm(tarFile)
// Move the extracted files to the destination
const folderName = tarName.slice(0, -4)
const folderPath = join(tarDir, folderName)
await mkdirP(dirname(dest))
await mv(folderPath, dest)
} else {
// extract the 7z file directly
await run7zip(file, dest)
}

return dest
}

async function run7zip(file: string, dest: string) {
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
await grantUserWriteAccess(dest)
return dest
}

/// install 7z if needed
Expand Down

0 comments on commit ff86c1b

Please sign in to comment.