Skip to content

Commit

Permalink
pathikrit#77 - copyTo with overwrite should not delete all of origina…
Browse files Browse the repository at this point in the history
…l files in target folder.
  • Loading branch information
jiminhsieh committed Jul 14, 2017
1 parent cf2d718 commit b24cab5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion core/src/main/scala/better/files/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge
*/
def copyTo(destination: File, overwrite: Boolean = false)(implicit copyOptions: File.CopyOptions = File.CopyOptions(overwrite)): destination.type = {
if (isDirectory) {//TODO: maxDepth?
if (overwrite) destination.delete(swallowIOExceptions = true)
Files.walkFileTree(path, new SimpleFileVisitor[Path] {
def newPath(subPath: Path): Path = destination.path.resolve(path.relativize(subPath))

Expand Down
2 changes: 2 additions & 0 deletions core/src/test/scala/better/files/FileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ class FileSpec extends CommonSpec {

it should "copy" in {
(fb / "t3" / "t4.txt").createIfNotExists(createParents = true).writeText("Hello World")
(fb / "t5" / "t5.txt").createIfNotExists(createParents = true).writeText("Scala Awesome")
cp(fb / "t3", fb / "t5")
(fb / "t5" / "t4.txt").contentAsString shouldEqual "Hello World"
(fb / "t5" / "t5.txt").contentAsString shouldEqual "Scala Awesome"
(fb / "t3").exists shouldBe true
}

Expand Down

0 comments on commit b24cab5

Please sign in to comment.