@@ -813,8 +813,10 @@ public static void copyFile(final File srcFile, final File destFile, final boole
813813 Files .copy (srcFile .toPath (), destFile .toPath (), copyOptions );
814814
815815 // On Windows, the last modified time is copied by default.
816- if (preserveFileDate ) {
817- setTimes (srcFile , destFile );
816+ if (preserveFileDate ) {
817+ if (!setTimes (srcFile , destFile )) {
818+ throw new IOException ("Cannot set the file time." );
819+ }
818820 }
819821 }
820822
@@ -2836,11 +2838,13 @@ private static File requireFileIfExists(final File file, final String name) {
28362838 *
28372839 * @param sourceFile The source file to query.
28382840 * @param targetFile The target file or directory to set.
2841+ * @return {@code true} if and only if the operation succeeded;
2842+ * {@code false} otherwise
28392843 * @throws NullPointerException if sourceFile is {@code null}.
28402844 * @throws NullPointerException if targetFile is {@code null}.
28412845 * @throws IOException if setting the last-modified time failed.
28422846 */
2843- private static void setTimes (final File sourceFile , final File targetFile ) throws IOException {
2847+ private static boolean setTimes (final File sourceFile , final File targetFile ) throws IOException {
28442848 Objects .requireNonNull (sourceFile , "sourceFile" );
28452849 Objects .requireNonNull (targetFile , "targetFile" );
28462850 try {
@@ -2849,9 +2853,10 @@ private static void setTimes(final File sourceFile, final File targetFile) throw
28492853 final BasicFileAttributeView destAttrView = Files .getFileAttributeView (targetFile .toPath (), BasicFileAttributeView .class );
28502854 // null guards are not needed; BasicFileAttributes.setTimes(...) is null safe
28512855 destAttrView .setTimes (srcAttr .lastModifiedTime (), srcAttr .lastAccessTime (), srcAttr .creationTime ());
2852- } catch (IOException unused ) {
2856+ return true ;
2857+ } catch (IOException ignored ) {
28532858 // Fallback: Only set modified time to match source file
2854- targetFile .setLastModified (sourceFile .lastModified ());
2859+ return targetFile .setLastModified (sourceFile .lastModified ());
28552860 }
28562861
28572862 // TODO: (Help!) Determine historically why setLastModified(File, File) needed PathUtils.setLastModifiedTime() if
0 commit comments