Skip to content

Commit

Permalink
core: fix file path separators (#660)
Browse files Browse the repository at this point in the history
fixes #657

I'm not sure it's worth making it testable.
  • Loading branch information
fwbrasil authored Sep 13, 2024
1 parent 131db14 commit 9450eee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion kyo-bench/src/main/scala/kyo/bench/Registry.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kyo.bench

import java.io.BufferedReader
import java.io.File
import java.io.InputStream
import java.io.InputStreamReader
import scala.jdk.CollectionConverters.*
Expand Down Expand Up @@ -28,7 +29,7 @@ object Registry:

private def findClasses(packageName: String): Seq[Class[?]] =
val stream: InputStream = getClass.getClassLoader()
.getResourceAsStream(packageName.replaceAll("[.]", "/"))
.getResourceAsStream(packageName.replaceAll("[.]", File.separator))
val reader = new BufferedReader(new InputStreamReader(stream))
reader.lines()
.filter(line => line.endsWith(".class"))
Expand Down
8 changes: 4 additions & 4 deletions kyo-core/jvm/src/main/scala/kyo/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.dirs.BaseDirectories
import dev.dirs.ProjectDirectories
import dev.dirs.UserDirectories
import java.io.BufferedReader
import java.io.File
import java.io.IOException
import java.lang.System as JSystem
import java.nio.*
Expand All @@ -21,7 +22,7 @@ import scala.jdk.StreamConverters.*

class Path private (val path: List[String]) derives CanEqual:

def toJava: JPath = Paths.get(path.mkString("/"))
def toJava: JPath = Paths.get(path.mkString(File.separator))
lazy val parts: List[Path.Part] = path

/** Methods to read files completely
Expand Down Expand Up @@ -346,7 +347,7 @@ class Path private (val path: List[String]) derives CanEqual:
(this eq that) || this.path == that.path
case _ => false

override def toString = s"Path(\"${path.mkString("/")}\")"
override def toString = s"Path(\"${path.mkString(File.separator)}\")"

end Path

Expand All @@ -362,8 +363,7 @@ object Path:
}
val javaPath = if flattened.isEmpty then Paths.get("") else Paths.get(flattened.head, flattened.tail*)
val normalizedPath = javaPath.normalize().toString

new Path(if normalizedPath.isEmpty then Nil else normalizedPath.split("/").toList)
new Path(if normalizedPath.isEmpty then Nil else normalizedPath.split(File.separator).toList)
end apply

def apply(path: Part*): Path =
Expand Down

0 comments on commit 9450eee

Please sign in to comment.