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 b99b3f9 Throw an IOException if calling setLastModified() fails. b99b3f9 is described below commit b99b3f9f484074454c6d67ec658a4e0e8555ffd2 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Mon Aug 10 20:15:43 2020 -0400 Throw an IOException if calling setLastModified() fails. --- src/main/java/org/apache/commons/io/FileUtils.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index e4bb062..ad728d3 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -1326,10 +1326,9 @@ public class FileUtils { * @param preserveFileDate whether to preserve the file date * @param exclusionList List of files and directories to exclude from the copy, may be null * @param copyOptions options specifying how the copy should be done, for example {@link StandardCopyOption}. - * @return whether the operation succeeded * @throws IOException if an error occurs */ - private static boolean doCopyDirectory(final File srcDir, final File destDir, final FileFilter filter, + private static void doCopyDirectory(final File srcDir, final File destDir, final FileFilter filter, final boolean preserveFileDate, final List<String> exclusionList, final CopyOption... copyOptions) throws IOException { // recurse @@ -1362,9 +1361,8 @@ public class FileUtils { // Do this last, as the above has probably affected directory metadata if (preserveFileDate) { - return destDir.setLastModified(srcDir.lastModified()); + setLastModified(srcDir, destDir); } - return true; } /** @@ -1386,7 +1384,7 @@ public class FileUtils { * @throws IllegalArgumentException "Negative size" if the file is truncated so that the size is less than the * position */ - private static boolean doCopyFile(final File srcFile, final File destFile, final boolean preserveFileDate, CopyOption... copyOptions) + private static void doCopyFile(final File srcFile, final File destFile, final boolean preserveFileDate, CopyOption... copyOptions) throws IOException { if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); @@ -1402,7 +1400,22 @@ public class FileUtils { // TODO IO-386: Do we still need this check? checkEqualSizes(srcFile, destFile, srcFile.length(), destFile.length()); - return preserveFileDate ? destFile.setLastModified(srcFile.lastModified()) : true; + if (preserveFileDate) { + setLastModified(srcFile, destFile); + } + } + + /** + * Sets the given {@code destFile}'s last modified date to the value from {@code srcFile}. + * + * @param sourceFile The source file to query. + * @param targetFile The target file to set. + * @throws IOException if an error occurs + */ + private static void setLastModified(final File sourceFile, final File targetFile) throws IOException { + if (!targetFile.setLastModified(sourceFile.lastModified())) { + throw new IOException("Failed setLastModified on " + sourceFile); + } } //-----------------------------------------------------------------------