Skip to content

Commit

Permalink
Prefer File.getCanonicalFile over Path.normalize
Browse files Browse the repository at this point in the history
The former normalizes Windows 8.3 paths to long paths, whereas the
latter doesn't.
  • Loading branch information
alexarchambault committed May 23, 2021
1 parent 53c33bb commit 3e43f15
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions os/src/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,13 @@ object Path {
throw PathError.AbsolutePathOutsideRoot
}

val normalized = f.normalize()
fromNIO(f)
}

private def fromNIO(p: java.nio.file.Path): Path = {
// On Windows, File.getCanonicalFile normalizes 8.3 paths as long paths,
// whereas Path.normalize doesn't. So we use the former here.
val normalized = p.toFile.getCanonicalFile.toPath
new Path(normalized)
}

Expand Down Expand Up @@ -437,8 +443,8 @@ class Path private[os](val wrapped: java.nio.file.Path)

def /(chunk: PathChunk): ThisType = {
if (chunk.ups > wrapped.getNameCount) throw PathError.AbsolutePathOutsideRoot
val resolved = wrapped.resolve(chunk.toString).normalize()
new Path(resolved)
val resolved = wrapped.resolve(chunk.toString)
Path.fromNIO(resolved)
}
override def toString = wrapped.toString

Expand Down

0 comments on commit 3e43f15

Please sign in to comment.