@@ -1326,10 +1326,9 @@ public static boolean directoryContains(final File directory, final File child)
13261326 * @param preserveFileDate whether to preserve the file date
13271327 * @param exclusionList List of files and directories to exclude from the copy, may be null
13281328 * @param copyOptions options specifying how the copy should be done, for example {@link StandardCopyOption}.
1329- * @return whether the operation succeeded
13301329 * @throws IOException if an error occurs
13311330 */
1332- private static boolean doCopyDirectory (final File srcDir , final File destDir , final FileFilter filter ,
1331+ private static void doCopyDirectory (final File srcDir , final File destDir , final FileFilter filter ,
13331332 final boolean preserveFileDate , final List <String > exclusionList , final CopyOption ... copyOptions )
13341333 throws IOException {
13351334 // recurse
@@ -1362,9 +1361,8 @@ private static boolean doCopyDirectory(final File srcDir, final File destDir, fi
13621361
13631362 // Do this last, as the above has probably affected directory metadata
13641363 if (preserveFileDate ) {
1365- return destDir . setLastModified (srcDir . lastModified () );
1364+ setLastModified (srcDir , destDir );
13661365 }
1367- return true ;
13681366 }
13691367
13701368 /**
@@ -1386,7 +1384,7 @@ private static boolean doCopyDirectory(final File srcDir, final File destDir, fi
13861384 * @throws IllegalArgumentException "Negative size" if the file is truncated so that the size is less than the
13871385 * position
13881386 */
1389- private static boolean doCopyFile (final File srcFile , final File destFile , final boolean preserveFileDate , CopyOption ... copyOptions )
1387+ private static void doCopyFile (final File srcFile , final File destFile , final boolean preserveFileDate , CopyOption ... copyOptions )
13901388 throws IOException {
13911389 if (destFile .exists () && destFile .isDirectory ()) {
13921390 throw new IOException ("Destination '" + destFile + "' exists but is a directory" );
@@ -1402,7 +1400,22 @@ private static boolean doCopyFile(final File srcFile, final File destFile, final
14021400 // TODO IO-386: Do we still need this check?
14031401 checkEqualSizes (srcFile , destFile , srcFile .length (), destFile .length ());
14041402
1405- return preserveFileDate ? destFile .setLastModified (srcFile .lastModified ()) : true ;
1403+ if (preserveFileDate ) {
1404+ setLastModified (srcFile , destFile );
1405+ }
1406+ }
1407+
1408+ /**
1409+ * Sets the given {@code destFile}'s last modified date to the value from {@code srcFile}.
1410+ *
1411+ * @param sourceFile The source file to query.
1412+ * @param targetFile The target file to set.
1413+ * @throws IOException if an error occurs
1414+ */
1415+ private static void setLastModified (final File sourceFile , final File targetFile ) throws IOException {
1416+ if (!targetFile .setLastModified (sourceFile .lastModified ())) {
1417+ throw new IOException ("Failed setLastModified on " + sourceFile );
1418+ }
14061419 }
14071420
14081421 //-----------------------------------------------------------------------
0 commit comments