-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: don't mkdir directories that already exist #7899
base: latest
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const { | |
mkdir, | ||
rm, | ||
symlink, | ||
access, | ||
} = require('node:fs/promises') | ||
const { moveFile } = require('@npmcli/fs') | ||
const PackageJson = require('@npmcli/package-json') | ||
|
@@ -123,10 +124,19 @@ module.exports = cls => class Reifier extends cls { | |
// we do NOT want to set ownership on this folder, especially | ||
// recursively, because it can have other side effects to do that | ||
// in a project directory. We just want to make it if it's missing. | ||
await mkdir(resolve(this.path), { recursive: true }) | ||
const resolvedPath = resolve(this.path) | ||
try { | ||
await access(resolvedPath) | ||
} catch (accessError) { | ||
if (accessError.code === 'ENOENT') { | ||
await mkdir(resolvedPath, { recursive: true }) | ||
} else { | ||
throw accessError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason tests are failing is because there aren't any that test for this scenario, i.e. an error other than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will any changes have to be made to this code to resolve the failing tests in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test will have to be added to cover that code path. |
||
} | ||
} | ||
|
||
// do not allow the top-level node_modules to be a symlink | ||
await this.#validateNodeModules(resolve(this.path, 'node_modules')) | ||
await this.#validateNodeModules(resolve(resolvedPath, 'node_modules')) | ||
} | ||
await this[_loadTrees](options) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note for future devs looking at this change. Any error other than
ENOENT
thataccess
gets is going to also be thrown if attemptingmkdir
. I think only ignoring that error is the correct one.