From 9a653d842fa50444233142b0da24645d99f181b3 Mon Sep 17 00:00:00 2001 From: Pive01 Date: Thu, 6 Apr 2023 09:06:06 +0200 Subject: [PATCH 1/3] Fixed bug that caused users not showing up --- scripts/windows/checkUser.cmd | 3 +-- ui/src/services/util/format.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/windows/checkUser.cmd b/scripts/windows/checkUser.cmd index 57a0908..9298da8 100644 --- a/scripts/windows/checkUser.cmd +++ b/scripts/windows/checkUser.cmd @@ -1,2 +1 @@ -dir \\wsl.localhost\%1\home | findstr /v /s /c:"." -:: exclude directories that starts with . (so "." and "..") +dir \\wsl.localhost\%1\home diff --git a/ui/src/services/util/format.ts b/ui/src/services/util/format.ts index ed1af43..72ee451 100644 --- a/ui/src/services/util/format.ts +++ b/ui/src/services/util/format.ts @@ -6,7 +6,7 @@ export function removeNullBytes(str: string): string { return str.split('').filter(char => char.codePointAt(0)).join(''); } -const EXCLUDED_WSL = ['docker-desktop', 'docker-desktop-data']; +const EXCLUDED_OS_WSL = ['docker-desktop', 'docker-desktop-data']; export function getOSsFromBinary(res: string): string[] { return res.split('\n').slice(3, -1) // get only the wsl items @@ -14,13 +14,16 @@ export function getOSsFromBinary(res: string): string[] { .slice(0, -2)) // remove status and final /r .sort((a, b) => b.length - a.length) // put the selected OS as first of the list (it has * in front) .map(distro => distro.slice(-1).pop()) // get only the name as string of the distro found (ex. [["*","Ubuntu"],["Fedora"]] => ["Ubuntu","Fedora"]) - .filter(distro => !EXCLUDED_WSL.includes(distro)); + .filter(distro => !EXCLUDED_OS_WSL.includes(distro)); } +const EXCLUDED_USER_WSL = ['.', '..', 'bytes']; + export function getUsersFromBinaryWindows(res: string): string[] { return res.split('\n').slice(5, -2) // get only directories rows .map(str => str.split(' ').at(-1) // get only dir name (ex "luca\r") - .slice(0, -1)); // remove newline + .slice(0, -1)) // remove newline + .filter(user => !EXCLUDED_USER_WSL.includes(user) && user.length>0); } export function getUsersFromBinaryUnix(res: string): string[] { From a8eedc4d445200c272881e1cd04f7f9accc00bb6 Mon Sep 17 00:00:00 2001 From: Pive01 Date: Thu, 6 Apr 2023 10:16:23 +0200 Subject: [PATCH 2/3] moved to a more reliable approach --- scripts/windows/checkUser.cmd | 2 +- ui/src/services/util/format.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/windows/checkUser.cmd b/scripts/windows/checkUser.cmd index 9298da8..4de2102 100644 --- a/scripts/windows/checkUser.cmd +++ b/scripts/windows/checkUser.cmd @@ -1 +1 @@ -dir \\wsl.localhost\%1\home +dir \\wsl.localhost\%1\home /d diff --git a/ui/src/services/util/format.ts b/ui/src/services/util/format.ts index 72ee451..8e4f5db 100644 --- a/ui/src/services/util/format.ts +++ b/ui/src/services/util/format.ts @@ -17,13 +17,13 @@ export function getOSsFromBinary(res: string): string[] { .filter(distro => !EXCLUDED_OS_WSL.includes(distro)); } -const EXCLUDED_USER_WSL = ['.', '..', 'bytes']; +const EXCLUDED_USER_WSL = ['[.]', '[..]', '\r']; export function getUsersFromBinaryWindows(res: string): string[] { - return res.split('\n').slice(5, -2) // get only directories rows - .map(str => str.split(' ').at(-1) // get only dir name (ex "luca\r") - .slice(0, -1)) // remove newline - .filter(user => !EXCLUDED_USER_WSL.includes(user) && user.length>0); + return res.split('\n').filter(string => string.startsWith('[')) // get only direcotires row (they are in form "[user1] [user2]" ) + .map(elem =>elem.split(' ').filter(item => item.length > 0 && !EXCLUDED_USER_WSL.includes(item)))// get only dir names + .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []) // combine multiple lines into one + .map(user => user.slice(1, -1)); // remove "[" and "]" from names } export function getUsersFromBinaryUnix(res: string): string[] { From 3fec365ec8b93c9273956892ba89c37b9e85d943 Mon Sep 17 00:00:00 2001 From: Luca Pivetta <36865043+Pive01@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:01:51 +0200 Subject: [PATCH 3/3] Update ui/src/services/util/format.ts Co-authored-by: Waldemar Hummer --- ui/src/services/util/format.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/services/util/format.ts b/ui/src/services/util/format.ts index 8e4f5db..e30a873 100644 --- a/ui/src/services/util/format.ts +++ b/ui/src/services/util/format.ts @@ -20,7 +20,7 @@ export function getOSsFromBinary(res: string): string[] { const EXCLUDED_USER_WSL = ['[.]', '[..]', '\r']; export function getUsersFromBinaryWindows(res: string): string[] { - return res.split('\n').filter(string => string.startsWith('[')) // get only direcotires row (they are in form "[user1] [user2]" ) + return res.split('\n').filter(string => string.startsWith('[')) // get only directory rows (they are in form "[user1] [user2]" ) .map(elem =>elem.split(' ').filter(item => item.length > 0 && !EXCLUDED_USER_WSL.includes(item)))// get only dir names .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []) // combine multiple lines into one .map(user => user.slice(1, -1)); // remove "[" and "]" from names