checkWSLDistroMatch function
Check if a WSL path belongs to a specific distro.
Implementation
bool checkWSLDistroMatch(String path, String distroName) {
// Check \\wsl$\distro paths
final wslMatch = RegExp(
r'^\\\\wsl\$\\([^\\]+)',
caseSensitive: false,
).firstMatch(path);
if (wslMatch != null) {
return wslMatch.group(1)!.toLowerCase() == distroName.toLowerCase();
}
// Check \\wsl.localhost\distro paths
final localhostMatch = RegExp(
r'^\\\\wsl\.localhost\\([^\\]+)',
caseSensitive: false,
).firstMatch(path);
if (localhostMatch != null) {
return localhostMatch.group(1)!.toLowerCase() == distroName.toLowerCase();
}
// Non-WSL paths are always valid
return true;
}