From 7519598be5ce9efefcc9a39a207bb88682ee3fa5 Mon Sep 17 00:00:00 2001 From: kalexey89 Date: Tue, 16 Feb 2021 17:06:15 +0300 Subject: [PATCH 1/2] fix(wsl): mount point issue closes #223 --- index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 06e566d..2780b80 100644 --- a/index.js +++ b/index.js @@ -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 () { @@ -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 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; From ea8ec6a1bcd38b498c897946da5687b2cd3e9635 Mon Sep 17 00:00:00 2001 From: kalexey89 Date: Tue, 16 Feb 2021 17:08:13 +0300 Subject: [PATCH 2/2] style: remove spaces before and after parens --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2780b80..13147d0 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ const getWslDrivesMountPoint = (() => { return defaultMountPoint; } - const configContent = await pReadFile(configFilePath, { encoding: 'utf8' }); + const configContent = await pReadFile(configFilePath, {encoding: 'utf8'}); const configMountPoint = /root\s*=\s*(.*)/g.exec(configContent); if (!configMountPoint) {