FileUtils.doCopyFile uses different methods to check the file
sizes.
The method org.apache.commons.io.FileUtils.copyFile(File, File,
CopyOption...) no longer checks file sizes.
FileUtils.copyFile methods throw an unnecessary "Failed to
copy full contents from" exception.
Remove test that does not reflect what happens on disk since we use
Files.copy(Path,Path,CopyOptions)
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -183,11 +183,14 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-772" dev="ggregory" type="fix" due-to="Dan Ziemba, Gary Gregory">
Confusing Javadoc on IOUtils#resourceToURL() and other resource* methods.
</action>
+ <action issue="IO-443" dev="ggregory" type="fix" due-to="Dan Ziemba, Gary Gregory">
+ FileUtils.copyFile methods throw an unnecessary "Failed to copy full contents from" exception.
+ </action>
<action issue="IO-564" dev="ggregory" type="fix" due-to="Hao Zhong, Bernd Eckenfels, Pascal Schumacher, Gary Gregory">
Pick up Javadoc from super for override write() methods in AbstractByteArrayOutputStream and ByteArrayOutputStream.
</action>
<action dev="ggregory" type="fix" due-to="Marc Wrobel">
- Fix minor typos #367
+ Fix minor typos #367.
</action>
<action issue="IO-776" dev="kinow" type="fix" due-to="Chris Povirk">
Fix parameters to requireNonNull call in DeferredOutputSteam #368.
@@ -195,6 +198,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Fix PathUtils.copyFileToDirectory(URL,Path,CopyOption[]).
</action>
+ <action issue="IO-386" dev="ggregory" type="fix" due-to="Sebb, Bernd Eckenfels, zhipengxu, Gary Gregory">
+ FileUtils.doCopyFile uses different methods to check the file sizes.
+ </action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add GitHub coverage.yml.

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
@@ -829,7 +829,6 @@ public static void copyFile(final File srcFile, final File destFile, final boole
* @throws NullPointerException if any of the given {@link File}s are {@code null}.
* @throws FileNotFoundException if the source does not exist.
* @throws IllegalArgumentException if source is not a file.
- * @throws IOException if the output file length is not the same as the input file length after the copy completes.
* @throws IOException if an I/O error occurs.
* @see StandardCopyOption
* @since 2.9.0
@@ -843,12 +842,8 @@ public static void copyFile(final File srcFile, final File destFile, final CopyO
if (destFile.exists()) {
requireCanWrite(destFile, "destFile");
}
-
// On Windows, the last modified time is copied by default.
Files.copy(srcFile.toPath(), destFile.toPath(), copyOptions);
-
- // TODO IO-386: Do we still need this check?
- requireEqualSizes(srcFile, destFile, srcFile.length(), destFile.length());
}
/**
@@ -2771,22 +2766,6 @@ private static File requireDirectoryIfExists(final File directory, final String
return directory;
}
- /**
- * Requires that two file lengths are equal.
- *
- * @param srcFile Source file.
- * @param destFile Destination file.
- * @param srcLen Source file length.
- * @param dstLen Destination file length
- * @throws IOException Thrown when the given sizes are not equal.
- */
- private static void requireEqualSizes(final File srcFile, final File destFile, final long srcLen, final long dstLen) throws IOException {
- if (srcLen != dstLen) {
- throw new IOException(
- "Failed to copy full contents from '" + srcFile + "' to '" + destFile + "' Expected length: " + srcLen + " Actual: " + dstLen);
- }
- }
-
/**
* Requires that the given {@link File} exists and throws an {@link IllegalArgumentException} if it doesn't.
*

MODIFY
src/test/java/org/apache/commons/io/FileUtilsTest.java
src/test/java/org/apache/commons/io/FileUtilsTest.java
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
@@ -1588,22 +1587,6 @@ public void testGetUserDirectoryPath() {
assertEquals(System.getProperty("user.home"), FileUtils.getUserDirectoryPath());
}
- // This test relies on FileUtils.copyFile using File.length to check the output size
- @Test
- public void testIncorrectOutputSize() {
- final File inFile = new File("pom.xml");
- final File outFile = new ShorterFile("target/pom.tmp"); // it will report a shorter file
- try {
- FileUtils.copyFile(inFile, outFile);
- fail("Expected IOException");
- } catch (final Exception e) {
- final String msg = e.toString();
- assertTrue(msg.contains("Failed to copy full contents"), msg);
- } finally {
- outFile.delete(); // tidy up
- }
- }
-
@Test
public void testIO276() throws Exception {
final File dir = new File("target", "IO276");

[IO-386] FileUtils.doCopyFile uses different methods to check the file
sizes.

- The method org.apache.commons.io.FileUtils.copyFile(File, File,
CopyOption...) no longer checks file sizes.
- [IO-443] FileUtils.copyFile methods throw an unnecessary "Failed to
copy full contents from" exception.
- Remove test that does not reflect what happens on disk since we use
Files.copy(Path,Path,CopyOptions)