This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 77a67f06 [IO-386] FileUtils.doCopyFile uses different methods to check 
the file sizes.
77a67f06 is described below

commit 77a67f06433e8561b70fecc14b6ce93ad0cf5e5f
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Mon Aug 8 10:32:35 2022 -0400

    [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)
---
 src/changes/changes.xml                             |  8 +++++++-
 src/main/java/org/apache/commons/io/FileUtils.java  | 21 ---------------------
 .../java/org/apache/commons/io/FileUtilsTest.java   | 17 -----------------
 3 files changed, 7 insertions(+), 39 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4611da4d..342b5c0a 100644
--- a/src/changes/changes.xml
+++ b/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.
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java 
b/src/main/java/org/apache/commons/io/FileUtils.java
index b0098697..24805864 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -829,7 +829,6 @@ public class FileUtils {
      * @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 class FileUtils {
         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 @@ public class FileUtils {
         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.
      *
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java 
b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 0069683d..afda381b 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 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 class FileUtilsTest extends AbstractTempDirTest {
         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");

Reply via email to