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 4d8dcd26 Missing throw in org.apache.commons.io.FileUtils.copyFile(File, File, boolean, CopyOption...) 4d8dcd26 is described below commit 4d8dcd264fd700c96062d661ac3b0bcf87164467 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Apr 28 16:05:14 2023 -0400 Missing throw in org.apache.commons.io.FileUtils.copyFile(File, File, boolean, CopyOption...) --- src/main/java/org/apache/commons/io/FileUtils.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 51746461..6c832768 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -813,8 +813,10 @@ public class FileUtils { Files.copy(srcFile.toPath(), destFile.toPath(), copyOptions); // On Windows, the last modified time is copied by default. - if(preserveFileDate) { - setTimes(srcFile, destFile); + if (preserveFileDate) { + if (!setTimes(srcFile, destFile)) { + throw new IOException("Cannot set the file time."); + } } } @@ -2836,11 +2838,13 @@ public class FileUtils { * * @param sourceFile The source file to query. * @param targetFile The target file or directory to set. + * @return {@code true} if and only if the operation succeeded; + * {@code false} otherwise * @throws NullPointerException if sourceFile is {@code null}. * @throws NullPointerException if targetFile is {@code null}. * @throws IOException if setting the last-modified time failed. */ - private static void setTimes(final File sourceFile, final File targetFile) throws IOException { + private static boolean setTimes(final File sourceFile, final File targetFile) throws IOException { Objects.requireNonNull(sourceFile, "sourceFile"); Objects.requireNonNull(targetFile, "targetFile"); try { @@ -2849,9 +2853,10 @@ public class FileUtils { final BasicFileAttributeView destAttrView = Files.getFileAttributeView(targetFile.toPath(), BasicFileAttributeView.class); // null guards are not needed; BasicFileAttributes.setTimes(...) is null safe destAttrView.setTimes(srcAttr.lastModifiedTime(), srcAttr.lastAccessTime(), srcAttr.creationTime()); - } catch (IOException unused) { + return true; + } catch (IOException ignored) { // Fallback: Only set modified time to match source file - targetFile.setLastModified(sourceFile.lastModified()); + return targetFile.setLastModified(sourceFile.lastModified()); } // TODO: (Help!) Determine historically why setLastModified(File, File) needed PathUtils.setLastModifiedTime() if