Skip to content
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

Close the file descriptor if exiting upload via an error. #80

Merged
merged 1 commit into from
Nov 26, 2018
Merged
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
10 changes: 10 additions & 0 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ function upload (arg, pkg, isRetry, cached) {
auth: auth
}

function closeFile () {
if (!npm.config.get('dry-run')) {
params.body.close()
}
}

// registry-frontdoor cares about the access level, which is only
// configurable for scoped packages
if (config.get('access')) {
Expand Down Expand Up @@ -195,13 +201,17 @@ function upload (arg, pkg, isRetry, cached) {
return BB.fromNode((cb) => {
npm.commands.unpublish([pkg._id], cb)
}).finally(() => {
// close the file we are trying to upload, we will open it again.
closeFile()
// ignore errors. Use the force. Reach out with your feelings.
return upload(arg, pkg, true, cached).catch(() => {
// but if it fails again, then report the first error.
throw err
})
})
} else {
// close the file we are trying to upload, all attempts to resume will open it again
closeFile()
throw err
}
})
Expand Down