From f4df68ab2f37154bce40acde3cf69721275295d7 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Tue, 16 Feb 2021 19:02:42 +0300 Subject: [PATCH] WSL: Fix mount point issue (#224) --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 06e566d..13147d0 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 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;