diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index 8a1cae9f..028bf58f 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -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)) + () } /** diff --git a/io/src/test/scala/sbt/io/IOSpec.scala b/io/src/test/scala/sbt/io/IOSpec.scala index c6e0619e..e8b96fe5 100644 --- a/io/src/test/scala/sbt/io/IOSpec.scala +++ b/io/src/test/scala/sbt/io/IOSpec.scala @@ -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