Skip to content

Commit

Permalink
Merge pull request #1084 from jfkw/is_wsl1_or_wsl2
Browse files Browse the repository at this point in the history
Update is_wsl to match osrelease spellings under both WSL1 and WSL2
  • Loading branch information
teclator committed Jul 24, 2020
2 parents 3086f9f + 8b4cdf3 commit e9cd9ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion library/general/src/modules/Arch.rb
Expand Up @@ -477,7 +477,11 @@ def x11_setup_needed
#
# @return [Boolean] true if runs on WSL; false otherwise
def is_wsl
SCR.Read(path(".target.string"), "/proc/sys/kernel/osrelease").to_s.include?("-Microsoft")
# As of 2020-07-24 /proc/sys/kernel/osrelease contains
# "4.4.0-19041-Microsoft" on wsl1 and
# "4.19.104-microsoft-standard" on wsl2.
# Match on lowercase "-microsoft"
SCR.Read(path(".target.string"), "/proc/sys/kernel/osrelease").to_s.downcase.include?("-microsoft")
end

publish function: :architecture, type: "string ()"
Expand Down
12 changes: 10 additions & 2 deletions library/general/test/arch_test.rb
Expand Up @@ -135,8 +135,16 @@
.and_return(osrelease)
end

context "when it runs on a Microsoft kernel" do
let(:osrelease) { "5.3.11-Microsoft" }
context "when it runs on a Microsoft kernel under WSL1" do
let(:osrelease) { "4.4.0-19041-Microsoft" }

it "returns true" do
expect(Yast::Arch.is_wsl).to eq(true)
end
end

context "when it runs on a Microsoft kernel under WSL2" do
let(:osrelease) { "4.19.104-microsoft-standard" }

it "returns true" do
expect(Yast::Arch.is_wsl).to eq(true)
Expand Down
6 changes: 6 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jul 24 08:06:27 UTC 2020 - Jeff Kowalczyk <jkowalczyk@suse.com>

- update is_wsl function to match wsl1 and wsl2 osrelease spellings
(boo#1174183)

-------------------------------------------------------------------
Thu Jul 23 14:03:42 UTC 2020 - José Iván López González <jlopez@suse.com>

Expand Down

0 comments on commit e9cd9ae

Please sign in to comment.