-
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?
Conversation
Resolution attempt for npm#6412. Unfortunately, resolution of that issue introduces another error; `Tracker "idealTree" already exists`.
npm i
attempts to mkdir
root directories on WindowsAddressed style and syntax issues as per GitHub Workflows feedback.
Now using `access` from `node:fs/promises` instead of `existsSync` from `node:fs`.
|
Now using single-quotes instead of double-quotes.
Ah, it appears I accidentally used double-quotes instead of single-quotes for the string. |
Oh shoot, sorry I forgot this was the cli repo. Yeah you gotta either be in the arborist directory or specify the workspace. I'll have to remember that when suggesting that in the future. |
await access(resolvedPath) | ||
} catch (accessError) { | ||
if (accessError.code === 'ENOENT') { | ||
await mkdir(resolvedPath, { recursive: true }) |
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
that access
gets is going to also be thrown if attempting mkdir
. I think only ignoring that error is the correct one.
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 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.
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.
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 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.
This pull request aims to resolve #6412, by making checks for whether a project's working directory already exists, before attempting to
mkdir
it.This effectively prevents
reify.js
from accidentally executingmkdir
on root drive letters on Windows, likemkdir "D:/"
for example, as the Windows operating system prohibits such operations.The resolution of #6412 will inevitably introduce the
npm error Tracker "idealTree" already exists
issue, however I believe that is an issue separate from #6412, and that separate issue was already documented before, #7596 being a good example of one of those documentations (in my opinion).As can be seen in #6412, this pull request makes changes to the following line of code in
reify.js
.Of course, should one attempt to execute
npm i
in a drive letter that does not exist, then this error in my opinion should take place, informing the user that said drive letter and the path within cannot be created, and that error will take place. However this error in my opinion should not take place on existing drives, hence this pull request.Additional info
/workspaces/arborist/lib/arborist/reify.js
line126
npm i
tries to recreate root directory (drive letter) in Windows #6412