From fd44104bd147a3528f59a859f8885404a14ed2a0 Mon Sep 17 00:00:00 2001 From: philwalk Date: Wed, 15 Nov 2023 09:57:42 -0700 Subject: [PATCH] Fix for Windows `os.root()` with slash error (#235) This also adds a unit test. Pull request: https://github.com/com-lihaoyi/os-lib/pull/235 --- os/src-jvm/package.scala | 2 +- os/src-native/package.scala | 2 +- os/test/src-jvm/PathTestsCustomFilesystem.scala | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/os/src-jvm/package.scala b/os/src-jvm/package.scala index 300c1546..b0414bdf 100644 --- a/os/src-jvm/package.scala +++ b/os/src-jvm/package.scala @@ -15,7 +15,7 @@ package object os { def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = { val path = Path(fileSystem.getPath(root)) - assert(path.root == root, s"$root is not a root path") + assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path") path } diff --git a/os/src-native/package.scala b/os/src-native/package.scala index 9f6121f3..dcaaa4e7 100644 --- a/os/src-native/package.scala +++ b/os/src-native/package.scala @@ -12,7 +12,7 @@ package object os { def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = { val path = Path(fileSystem.getPath(root)) - assert(path.root == root, s"$root is not a root path") + assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path") path } diff --git a/os/test/src-jvm/PathTestsCustomFilesystem.scala b/os/test/src-jvm/PathTestsCustomFilesystem.scala index 6ffd21a9..3b05265f 100644 --- a/os/test/src-jvm/PathTestsCustomFilesystem.scala +++ b/os/test/src-jvm/PathTestsCustomFilesystem.scala @@ -226,8 +226,10 @@ object PathTestsCustomFilesystem extends TestSuite { val testWindows = Tests { test("cRootPath") { - val p = os.root("C:\\") / "Users" - assert(p.toString == "C:\\Users") + val p1 = os.root("C:\\") / "Users" + assert(p1.toString == "C:\\Users") + val p2 = os.root("C:/") / "Users" + assert(p2.toString == "C:\\Users") } }