Skip to content

fix: use temp dir for tar extraction on all platforms #3170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ async function install (gyp, argv) {
// download the tarball and extract!
// Ommited on Windows if only new node.lib is required

// on Windows there can be file errors from tar if parallel installs
// there can be file errors from tar if parallel installs
// are happening (not uncommon with multiple native modules) so
// extract the tarball to a temp directory first and then copy over
const tarExtractDir = win ? await fs.mkdtemp(path.join(os.tmpdir(), 'node-gyp-tmp-')) : devDir
const tarExtractDir = await fs.mkdtemp(path.join(os.tmpdir(), 'node-gyp-tmp-'))

try {
if (shouldDownloadTarball) {
Expand Down Expand Up @@ -277,17 +277,13 @@ async function install (gyp, argv) {
}

// copy over the files from the temp tarball extract directory to devDir
if (tarExtractDir !== devDir) {
await copyDirectory(tarExtractDir, devDir)
}
await copyDirectory(tarExtractDir, devDir)
} finally {
if (tarExtractDir !== devDir) {
try {
// try to cleanup temp dir
await fs.rm(tarExtractDir, { recursive: true, maxRetries: 3 })
} catch {
log.warn('failed to clean up temp tarball extract directory')
}
try {
// try to cleanup temp dir
await fs.rm(tarExtractDir, { recursive: true, maxRetries: 3 })
} catch {
log.warn('failed to clean up temp tarball extract directory')
}
}

Expand Down
Loading