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

fix: don't mkdir directories that already exist #7899

Open
wants to merge 4 commits into
base: latest
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
14 changes: 12 additions & 2 deletions workspaces/arborist/lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
mkdir,
rm,
symlink,
access,
} = require('node:fs/promises')
const { moveFile } = require('@npmcli/fs')
const PackageJson = require('@npmcli/package-json')
Expand Down Expand Up @@ -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 })
Copy link
Member

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 that access gets is going to also be thrown if attempting mkdir. I think only ignoring that error is the correct one.

} else {
throw accessError
Copy link
Member

Choose a reason for hiding this comment

The 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 ENOENT happening.

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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)

Expand Down
Loading