Browse Source

Improved heuristics on file timestamp granularity by adding an NTFS category and checking for it

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278110 13f79535-47bb-0310-9956-ffa450edef68
master
Bruce Atherton 20 years ago
parent
commit
3928b4fa9d
1 changed files with 18 additions and 4 deletions
  1. +18
    -4
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 18
- 4
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -66,6 +66,8 @@ public class FileUtils {

private static boolean onNetWare = Os.isFamily("netware");
private static boolean onDos = Os.isFamily("dos");
private static boolean onWin9x = Os.isFamily("win9x");
private static boolean onWindows = Os.isFamily("windows");

private static final int BUF_SIZE = 8192;

@@ -84,6 +86,12 @@ public class FileUtils {
*/
public static final long UNIX_FILE_TIMESTAMP_GRANULARITY = 1000;

/**
* The granularity of timestamps under the NT File System.
* NTFS has a granularity of 100 nanoseconds, which is less
* than 1 millisecond, so we set this to 0.
*/
public static final long NTFS_FILE_TIMESTAMP_GRANULARITY = 0;

// stolen from FilePathToURI of the Xerces-J team
static {
@@ -1339,13 +1347,19 @@ public class FileUtils {
* Get the granularity of file timestamps.
* The choice is made based on OS, which is incorrect--it should really be
* by filesystem. We do not have an easy way to probe for file systems,
* however.
* however, so this heuristic gives us a decent default.
* @return the difference, in milliseconds, which two file timestamps must have
* in order for the two files to be given a creation order.
* in order for the two files to be considered to have different timestamps.
*/
public long getFileTimestampGranularity() {
return onDos
? FAT_FILE_TIMESTAMP_GRANULARITY : UNIX_FILE_TIMESTAMP_GRANULARITY;
if (onWin9x) {
return FAT_FILE_TIMESTAMP_GRANULARITY;
} else if (onWindows) {
return NTFS_FILE_TIMESTAMP_GRANULARITY;
} else if (onDos) {
return FAT_FILE_TIMESTAMP_GRANULARITY;
}
return UNIX_FILE_TIMESTAMP_GRANULARITY;
}

/**


Loading…
Cancel
Save