Skip to content

Commit 05b5657

Browse files
committed
borrow detectwsl implementation from Julia
1 parent 524f492 commit 05b5657

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/helpers.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# Vendored from Pluto.jl#src/notebook/path helpers.jl
2-
# from https://github.com/JuliaLang/julia/pull/36425
3-
function detectwsl()
4-
Sys.islinux() &&
5-
isfile("/proc/sys/kernel/osrelease") &&
6-
occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String))
1+
@static if isdefined(Sys, :detectwsl)
2+
const detectwsl = Sys.detectwsl
3+
else
4+
# Borrowed from Julia (MIT license)
5+
# https://github.com/JuliaLang/julia/blob/726c816b9590d748345fb615b76b685c79eafd0d/base/sysinfo.jl#L549-L555
6+
# https://github.com/JuliaLang/julia/pull/57069
7+
function detectwsl()
8+
# We use the same approach as canonical/snapd do to detect WSL
9+
islinux() && (
10+
isfile("/proc/sys/fs/binfmt_misc/WSLInterop")
11+
|| isdir("/run/WSL")
12+
)
13+
end
714
end

0 commit comments

Comments
 (0)