Skip to content

Commit b6281ec

Browse files
Pive01whummer
andauthored
fix(missing user): changed logic to get users (#33)
* Fixed bug that caused users not showing up * moved to a more reliable approach * Update ui/src/services/util/format.ts Co-authored-by: Waldemar Hummer <waldemar.hummer@gmail.com> --------- Co-authored-by: Waldemar Hummer <waldemar.hummer@gmail.com>
1 parent b3803a7 commit b6281ec

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

scripts/windows/checkUser.cmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
dir \\wsl.localhost\%1\home | findstr /v /s /c:"."
2-
:: exclude directories that starts with . (so "." and "..")
1+
dir \\wsl.localhost\%1\home /d

ui/src/services/util/format.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ export function removeNullBytes(str: string): string {
66
return str.split('').filter(char => char.codePointAt(0)).join('');
77
}
88

9-
const EXCLUDED_WSL = ['docker-desktop', 'docker-desktop-data'];
9+
const EXCLUDED_OS_WSL = ['docker-desktop', 'docker-desktop-data'];
1010

1111
export function getOSsFromBinary(res: string): string[] {
1212
return res.split('\n').slice(3, -1) // get only the wsl items
1313
.map(str => removeNullBytes(str).split(' ').filter((subStr: string) => subStr.length > 0) // remove space and null bytes
1414
.slice(0, -2)) // remove status and final /r
1515
.sort((a, b) => b.length - a.length) // put the selected OS as first of the list (it has * in front)
1616
.map(distro => distro.slice(-1).pop()) // get only the name as string of the distro found (ex. [["*","Ubuntu"],["Fedora"]] => ["Ubuntu","Fedora"])
17-
.filter(distro => !EXCLUDED_WSL.includes(distro));
17+
.filter(distro => !EXCLUDED_OS_WSL.includes(distro));
1818
}
1919

20+
const EXCLUDED_USER_WSL = ['[.]', '[..]', '\r'];
21+
2022
export function getUsersFromBinaryWindows(res: string): string[] {
21-
return res.split('\n').slice(5, -2) // get only directories rows
22-
.map(str => str.split(' ').at(-1) // get only dir name (ex "luca\r")
23-
.slice(0, -1)); // remove newline
23+
return res.split('\n').filter(string => string.startsWith('[')) // get only directory rows (they are in form "[user1] [user2]" )
24+
.map(elem =>elem.split(' ').filter(item => item.length > 0 && !EXCLUDED_USER_WSL.includes(item)))// get only dir names
25+
.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []) // combine multiple lines into one
26+
.map(user => user.slice(1, -1)); // remove "[" and "]" from names
2427
}
2528

2629
export function getUsersFromBinaryUnix(res: string): string[] {

0 commit comments

Comments
 (0)