Skip to content

Commit

Permalink
WSL: Fix mount point issue (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzalekon committed Feb 16, 2021
1 parent f0533c0 commit f4df68a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions index.js
Expand Up @@ -19,6 +19,10 @@ Get the mount point for fixed drives in WSL.
@returns {string} The mount point.
*/
const getWslDrivesMountPoint = (() => {
// Default value for "root" param
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
const defaultMountPoint = '/mnt/';

let mountPoint;

return async function () {
Expand All @@ -36,14 +40,17 @@ const getWslDrivesMountPoint = (() => {
} catch (_) {}

if (!isConfigFileExists) {
// Default value for "root" param
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
return '/mnt/';
return defaultMountPoint;
}

const configContent = await pReadFile(configFilePath, {encoding: 'utf8'});
const configMountPoint = /root\s*=\s*(.*)/g.exec(configContent);

if (!configMountPoint) {
return defaultMountPoint;
}

mountPoint = (/root\s*=\s*(.*)/g.exec(configContent)[1] || '').trim();
mountPoint = configMountPoint[1].trim();
mountPoint = mountPoint.endsWith('/') ? mountPoint : mountPoint + '/';

return mountPoint;
Expand Down

0 comments on commit f4df68a

Please sign in to comment.