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

WSL: Ignore commented mount point lines in wsl.conf #247

Merged

Conversation

haroonrafi
Copy link
Contributor

@haroonrafi haroonrafi commented May 5, 2021

The mount point is detected by reading wsl.conf (PR #219), but the regex does not ignore commented lines (see #246). This PR adds a negative lookbehind for lines starting with a hash character.

Fixes #246

@@ -42,7 +42,7 @@ const getWslDrivesMountPoint = (() => {
}

const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'});
const configMountPoint = /root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex results in an error: https://regex101.com/r/4pJXHS/1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see the error, has the regex101 test string changed? I just see #root and root below it which doesn't match, but that's no different to the original regex because it expects = after root. If I change the second line to root=/ it finds the match group.

I've tested this change locally with a #root comment directly above the actual mount point setting and it worked as expected.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It turns out I was looking at it with Safari and Safari doesn't support negative lookbehind.

@sindresorhus sindresorhus changed the title WSL: Ignore commented mount point lines in wsl.conf (Fixes #246) WSL: Ignore commented mount point lines in wsl.conf May 7, 2021
@sindresorhus sindresorhus merged commit 5b3b01c into sindresorhus:main May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WSL drive C mounting point incorrectly detected from commented lines in wsl.conf
2 participants