HADOOP-14434. Use MoveFileEx to allow renaming a file when the destination exists. Contributed by Lukas Majercak

(cherry picked from commit ef9e536a71)
This commit is contained in:
Chris Douglas 2017-05-17 17:21:03 -07:00
parent 94755e2d6d
commit 4bb0565443
2 changed files with 5 additions and 3 deletions

View File

@ -1204,7 +1204,7 @@ done:
if (!src) goto done; // exception was thrown
dst = (LPCWSTR) (*env)->GetStringChars(env, jdst, NULL);
if (!dst) goto done; // exception was thrown
if (!MoveFile(src, dst)) {
if (!MoveFileEx(src, dst, MOVEFILE_REPLACE_EXISTING)) {
throw_ioe(env, GetLastError());
}

View File

@ -532,7 +532,7 @@ public class TestNativeIO {
Assert.assertEquals(Errno.ENOENT, e.getErrno());
}
}
// Test renaming a file to itself. It should succeed and do nothing.
File sourceFile = new File(TEST_DIR, "source");
Assert.assertTrue(sourceFile.createNewFile());
@ -558,7 +558,9 @@ public class TestNativeIO {
}
}
FileUtils.deleteQuietly(TEST_DIR);
// Test renaming to an existing file
assertTrue(targetFile.exists());
NativeIO.renameTo(sourceFile, targetFile);
}
@Test(timeout=10000)