Skip to content

Commit

Permalink
Fix bug where milliseconds are read truncated in Java 8.
Browse files Browse the repository at this point in the history
This is fixed in Java 9, so a Java 8 host talking to a Java 9
host would always think its symlinks where out-of-date.
  • Loading branch information
stephenh committed Apr 16, 2018
1 parent 190b91a commit 3b613c5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/mirror/UpdateTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,18 @@ private Seq<Node> parents() {
private long sanityCheckTimestamp(long millis) {
long now = System.currentTimeMillis();
if (millis > now + oneHourInMillis) {
return now - oneMinuteInMillis;
} else {
return millis;
millis = now - oneMinuteInMillis;
}
// Due to a Java 8 bug, Files.getLastModifiedTime is truncated to seconds. This
// means watchman might return a file time of 1.234 seconds, but when we re-read
// the time with Files.getLastModifiedTime (which we only due for symlinks, to
// ensure LinkOption.NOFOLLOW_LINKS is used), we'll truncate it to 1 seconds.
//
// So, for now, continue doing all time stamp comparisons in truncated millis.
// (For a long time we truncated millis directly in WatchmanFileWatcher anyway.)
//
// https://stackoverflow.com/questions/24804618/get-file-mtime-with-millisecond-resolution-from-java
return millis / 1000 * 1000;
}

/** Visits nodes in the tree, in breadth-first order, continuing if {@visitor} returns true. */
Expand Down

0 comments on commit 3b613c5

Please sign in to comment.