Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

off by 1 error in os.copy (200USD Bounty) #167

Closed
bertlebee opened this issue Apr 21, 2023 · 1 comment · Fixed by #267
Closed

off by 1 error in os.copy (200USD Bounty) #167

bertlebee opened this issue Apr 21, 2023 · 1 comment · Fixed by #267
Labels
Milestone

Comments

@bertlebee
Copy link

bertlebee commented Apr 21, 2023

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.

Haoyi: To incentivize contribution, I'm putting a 200USD bounty on resolving this ticket. This is payable via bank transfer, and at my discretion in case of ambiguity.

@bertlebee
Copy link
Author

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"))

@lihaoyi lihaoyi changed the title off by 1 error in os.copy off by 1 error in os.copy (100USD Bounty) May 14, 2024
@lihaoyi lihaoyi changed the title off by 1 error in os.copy (100USD Bounty) off by 1 error in os.copy (200USD Bounty) May 14, 2024
@lefou lefou added this to the after 0.10.0 milestone May 15, 2024
lihaoyi pushed a commit that referenced this issue May 16, 2024
Fix an error where `os.copy(createFolders = true, mergeFolders = true)`
a directory to root throw a `PathError.AbsolutePathOutsideRoot` due to
calling `/up` on root.

The same issue (calling `/up` on root) is seen in `os.move`,
`os.copy.matching` and `os.move.matching` so this fixes those as well.
In case of `os.move` and `os.move.matching` moving a directory to root
should throw an error anyway but at least now it throws the correct
underlying error instead of `AbsolutePathOutsideRoot`.

Fix #167

Pull request: #267

---------

Co-authored-by: Tobias Roeser <le.petit.fou@web.de>
@lefou lefou added the bounty label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants