|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.lang.reflect.UndeclaredThrowableException;
|
23 | 23 | import java.nio.charset.Charset;
|
| 24 | +import java.nio.file.Files; |
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.Comparator;
|
26 | 27 | import java.util.Date;
|
@@ -940,12 +941,12 @@ protected boolean isUptodate()
|
940 | 941 | throws ArchiverException
|
941 | 942 | {
|
942 | 943 | final File zipFile = getDestFile();
|
943 |
| - final long destTimestamp = zipFile.lastModified(); |
944 |
| - if ( destTimestamp == 0 ) |
| 944 | + if ( !zipFile.exists() ) |
945 | 945 | {
|
946 | 946 | getLogger().debug( "isUp2date: false (Destination " + zipFile.getPath() + " not found.)" );
|
947 | 947 | return false; // File doesn't yet exist
|
948 | 948 | }
|
| 949 | + final long destTimestamp = getFileLastModifiedTime(zipFile); |
949 | 950 |
|
950 | 951 | final Iterator it = resources.iterator();
|
951 | 952 | if ( !it.hasNext() )
|
@@ -994,6 +995,26 @@ else if ( o instanceof AddedResourceCollection )
|
994 | 995 | return true;
|
995 | 996 | }
|
996 | 997 |
|
| 998 | + /** |
| 999 | + * Returns the last modified time in milliseconds of a file. |
| 1000 | + * It avoids the bug where milliseconds precision is lost on File#lastModified (JDK-8177809) on JDK8 and Linux. |
| 1001 | + * @param file The file where the last modified time will be returned for. |
| 1002 | + * @return The last modified time in milliseconds of the file. |
| 1003 | + * @throws ArchiverException In the case of an IOException, for example when the file does not exists. |
| 1004 | + */ |
| 1005 | + private long getFileLastModifiedTime( File file ) |
| 1006 | + throws ArchiverException |
| 1007 | + { |
| 1008 | + try |
| 1009 | + { |
| 1010 | + return Files.getLastModifiedTime( file.toPath() ).toMillis(); |
| 1011 | + } |
| 1012 | + catch ( IOException e ) |
| 1013 | + { |
| 1014 | + throw new ArchiverException( e.getMessage(), e ); |
| 1015 | + } |
| 1016 | + } |
| 1017 | + |
997 | 1018 | protected boolean checkForced()
|
998 | 1019 | throws ArchiverException
|
999 | 1020 | {
|
|
0 commit comments