Skip to content

Commit aa0fcb9

Browse files
committed
fix: use 7z for tar extraction on windows
1 parent 988cdb3 commit aa0fcb9

File tree

6 files changed

+37
-29
lines changed

6 files changed

+37
-29
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
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/setup/extract.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,53 @@ async function extractTarXzBy7zip(file: string, name: string, dest: string, stri
7878
throw new Error(`Invalid tar file: ${name}`)
7979
}
8080
// extract the compression first
81-
const tarDir = dirname(file)
81+
const tarDir = join(dirname(file), "sevenzip-temp")
8282
await run7zip(file, tarDir)
8383
// extract the tar
8484
const tarName = name.slice(0, -3)
8585
const tarFile = join(tarDir, tarName)
8686
await run7zip(tarFile, tarDir)
8787
await remove(tarFile)
8888
// move the extracted files to the destination
89-
const folderName = tarName.slice(0, -4)
90-
const folderPath = join(tarDir, folderName)
91-
info(`Moving ${folderPath} to ${dest}`)
92-
await move(folderPath, dest, { overwrite: true })
89+
info(`Moving ${tarDir} to ${dest}`)
90+
const files = await readdir(tarDir)
91+
await Promise.all(
92+
files.map(async (file) => {
93+
await move(join(tarDir, file), join(dest, file), { overwrite: true })
94+
}),
95+
)
96+
await remove(tarDir)
9397

9498
if (stripComponents) {
95-
await stripPathComponents(dest, folderName)
99+
await stripPathComponents(dest)
96100
}
97101
}
98102

99-
async function stripPathComponents(dest: string, folderName: string) {
103+
async function stripPathComponents(dest: string) {
104+
info(`Stripping path components from ${dest}`)
105+
100106
// get all subfolders in the folder
101-
const subFolders = await readdir(join(dest, folderName))
107+
const toStrip = await readdir(dest)
108+
if (toStrip.length !== 1) {
109+
throw new Error(`Expected 1 folder in ${dest}, got ${toStrip.length}`)
110+
}
111+
const subFolder = toStrip[0]
112+
const subFolderPath = join(dest, subFolder)
113+
const subFolderStat = await stat(subFolderPath)
114+
if (!subFolderStat.isDirectory()) {
115+
// if the subfolder is not a directory, do nothing
116+
warning(`Expected ${subFolderPath} to be a directory, got ${subFolderStat}.`)
117+
return
118+
}
119+
// for each child of the subfolder, move all files to the destination
120+
const subFiles = await readdir(subFolderPath)
102121
await Promise.all(
103-
subFolders.map(async (subFolder) => {
104-
const subFolderPath = join(dest, subFolder)
105-
if (!(await stat(subFolderPath)).isDirectory()) {
106-
// if the subfolder is not a directory, do nothing
107-
return
108-
}
109-
// for each subfolder, move all files to the destination
110-
const subFiles = await readdir(subFolderPath)
111-
await Promise.all(
112-
subFiles.map((subFile) => {
113-
return move(join(subFolderPath, subFile), join(dest, subFile), { overwrite: true })
114-
}),
115-
)
116-
// remove the subfolder
117-
await remove(subFolderPath)
118-
return
122+
subFiles.map((subFile) => {
123+
return move(join(subFolderPath, subFile), join(dest, subFile), { overwrite: true })
119124
}),
120125
)
126+
// remove the subfolder
127+
await remove(subFolderPath)
121128
}
122129

123130
async function run7zip(file: string, dest: string) {

src/utils/setup/setupBin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ async function tryDownload(name: string, version: string, url: string) {
138138
// try to download the package 4 times with 2 seconds delay
139139
const downloaded = await retry(
140140
() => {
141-
const downloadedFilePath = join(process.env.RUNNER_TEMP ?? tmpdir(), `${Date.now()}-${basename(url)}`)
141+
const prefix = `${Date.now()}-setup-cpp-`
142+
const downloadedFilePath = join(process.env.RUNNER_TEMP ?? tmpdir(), `${prefix}${basename(url)}`)
142143

143144
return downloadTool(url, downloadedFilePath)
144145
},

0 commit comments

Comments
 (0)