Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions scripts/windows/checkUser.cmd
Original file line number Diff line number Diff line change
@@ -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
13 changes: 8 additions & 5 deletions ui/src/services/util/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ 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
.map(str => removeNullBytes(str).split(' ').filter((subStr: string) => subStr.length > 0) // remove space and null bytes
.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[] {
Expand Down