|
1 |
| -import { mkdirP } from "@actions/io" |
| 1 | +import { basename, dirname, join } from "path" |
| 2 | +import { mkdirP, mv } from "@actions/io" |
2 | 3 | import { grantUserWriteAccess } from "admina"
|
3 | 4 | import { info, warning } from "ci-log"
|
4 | 5 | import { execa } from "execa"
|
| 6 | +import { rm } from "fs/promises" |
5 | 7 | import { installAptPack } from "setup-apt"
|
6 | 8 | import which from "which"
|
7 | 9 | import { setupSevenZip } from "../../sevenzip/sevenzip.js"
|
@@ -66,9 +68,33 @@ let sevenZip: string | undefined
|
66 | 68 |
|
67 | 69 | /// Extract 7z using 7z
|
68 | 70 | 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 | + await mv(folderPath, dest) |
| 87 | + } else { |
| 88 | + // extract the 7z file directly |
| 89 | + await run7zip(file, dest) |
| 90 | + } |
| 91 | + |
| 92 | + return dest |
| 93 | +} |
| 94 | + |
| 95 | +async function run7zip(file: string, dest: string) { |
69 | 96 | await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
|
70 | 97 | await grantUserWriteAccess(dest)
|
71 |
| - return dest |
72 | 98 | }
|
73 | 99 |
|
74 | 100 | /// install 7z if needed
|
|
0 commit comments