Skip to content

Commit

Permalink
Merge pull request #398 from eed3si9n/wip/move
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Dec 30, 2024
2 parents 4aab2d8 + d306d3b commit 88fbe96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 10 additions & 10 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1116,17 +1116,17 @@ object IO {
/**
* Moves the contents of `a` to the location specified by `b`.
* This method deletes any content already at `b` and creates any parent directories of `b` if they do not exist.
* It will first try `File.renameTo` and if that fails, resort to copying and then deleting the original file.
* In either case, the original File will not exist on successful completion of this method.
*/
def move(a: File, b: File): Unit = {
if (b.exists)
delete(b)
createDirectory(b.getParentFile)
if (!a.renameTo(b)) {
copyFile(a, b, true)
delete(a)
}
def move(a: File, b: File): Unit = move(a.toPath(), b.toPath())

/**
* Moves the contents of `a` to the location specified by `b`.
* This method deletes any content already at `b` and creates any parent directories of `b` if they do not exist.
*/
def move(a: NioPath, b: NioPath): Unit = {
createDirectory(b.getParent().toFile())
Retry(Files.move(a, b, StandardCopyOption.REPLACE_EXISTING))
()
}

/**
Expand Down
8 changes: 8 additions & 0 deletions io/src/test/scala/sbt/io/IOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ class IOSpec extends AnyFunSuite {
}
}

test("move should overwrite") {
IO.withTemporaryDirectory { dir =>
IO.touch(dir / "a.txt")
IO.touch(dir / "b.txt")
IO.move(dir / "a.txt", dir / "b.txt")
}
}

test("it should create valid jar files") {
IO.withTemporaryDirectory { tmpdir =>
import java.util.jar.Manifest
Expand Down

0 comments on commit 88fbe96

Please sign in to comment.