diff --git a/scripts/windows/checkUser.cmd b/scripts/windows/checkUser.cmd index 57a0908..4de2102 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 /d diff --git a/ui/src/services/util/format.ts b/ui/src/services/util/format.ts index ed1af43..e30a873 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 = ['[.]', '[..]', '\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 + 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 } export function getUsersFromBinaryUnix(res: string): string[] {