From 3e43f1575818a28453624ea1f0eef811c7c34038 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sun, 23 May 2021 17:35:01 +0200 Subject: [PATCH] Prefer File.getCanonicalFile over Path.normalize The former normalizes Windows 8.3 paths to long paths, whereas the latter doesn't. --- os/src/Path.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/os/src/Path.scala b/os/src/Path.scala index 10717e0b..7172801d 100644 --- a/os/src/Path.scala +++ b/os/src/Path.scala @@ -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) } @@ -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