Skip to content

path.dirname used in loop #7461

@dsoprea

Description

@dsoprea

I recently ran into an issue where there was a routine that creates a directory as well as all missing parent directories. It calls path.dirname() to get its parent directory and, if it doesn't exist, recurses into itself. Eventually it gets to some directory that exists and then works its way back, making the new subordinate directories.

In my case, I was providing a UNC (which is an expected use-case) and didn't have access to the share. So, the existence check was failing and it kept trying to move to the parent directory. Unfortunately, path.dirname()'s default functionality is to essentially return "\host\share" if given "\host\share" (because this is considered the "drive" and the highest-most root element). It won't peel away any further layers. This caused an infinite loop.

Can we modify path.dirname() to assert that what gets returned is not equaled to the argument?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.pathIssues and PRs related to the path subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions