os-lib icon indicating copy to clipboard operation
os-lib copied to clipboard

off by 1 error in os.copy

Open bertlebee opened this issue 2 years ago • 1 comments

https://scastie.scala-lang.org/5htwvdwbShivvYgwZZgqUg

Caused by: os.PathError$AbsolutePathOutsideRoot$: The path created has enough ..s that it would start outside the root directory
	at os.PathError$AbsolutePathOutsideRoot$.<clinit>(Path.scala:220)
	at os.Path.$div(Path.scala:462)
	at os.copy$.apply(FileOps.scala:179)

copying to a subpath works, copying to the root folder does not.

bertlebee avatar Apr 21 '23 22:04 bertlebee

import java.util.zip.*
import java.io.*
import java.nio.file.*
import scala.jdk.CollectionConverters.*

val jarLocation = os.home / "temp.jar"



println("copying:")
println(os.list(os.pwd).mkString("\n"))



val _ = new ZipOutputStream(new FileOutputStream(jarLocation.toIO)).close()

val jarPath = os.Path(FileSystems
  .newFileSystem(jarLocation.toNIO)
  .getRootDirectories()
  .asScala
  .head)

val subPath = jarPath / "subpath"
println(s"to $subPath")
os.copy(
  os.pwd,
  subPath,
  createFolders = true,
  mergeFolders = true
)
println("contents")
println(os.list(subPath).mkString("\n"))


println(s"copying to $jarPath")
os.copy(
  os.pwd,
  jarPath,
  createFolders = true,
  mergeFolders = true
)
println("contents")
println(os.list(jarPath).mkString("\n"))

bertlebee avatar Apr 23 '23 21:04 bertlebee