Skip to content

Commit

Permalink
Merge pull request #13306 from gradle/wolfs/vfs/normalize-both-last-m…
Browse files Browse the repository at this point in the history
…odified

Round both lastModified for CommonFileSystemTest
  • Loading branch information
wolfs committed Jun 8, 2020
2 parents 0708ec9 + 3aa0164 commit c478b9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,18 @@ class CommonFileSystemTest extends Specification {
}

def lastModified(File file) {
return Files.getFileAttributeView(file.toPath(), BasicFileAttributeView, LinkOption.NOFOLLOW_LINKS).readAttributes().lastModifiedTime().toMillis()
return maybeRoundLastModified(Files.getFileAttributeView(file.toPath(), BasicFileAttributeView, LinkOption.NOFOLLOW_LINKS).readAttributes().lastModifiedTime().toMillis())
}

def lastModified(FileMetadata fileMetadata) {
// Java 8 on Unix only captures the seconds in lastModified, so we cut it off the value returned from the filesystem as well
return maybeRoundLastModified(fileMetadata.lastModified)
}

private static maybeRoundLastModified(long lastModified) {
// Some Java 8 versions on Unix only capture the seconds in lastModified, so we cut off the milliseconds returned from the filesystem as well.
// For example, Oracle JDK 1.8.0_181-b13 does not capture milliseconds, while OpenJDK 1.8.0_242-b08 does.
return (JavaVersion.current().java9Compatible || OperatingSystem.current().windows)
? fileMetadata.lastModified
: fileMetadata.lastModified.intdiv(1000) * 1000
? lastModified
: lastModified.intdiv(1000) * 1000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class NativePlatformBackedFileMetadataAccessorTest extends AbstractFileMetadataA
}

private static maybeRoundLastModified(long lastModified) {
// Java 8 on Unix only captures the seconds in lastModified, so we cut it off the value returned from the filesystem as well
// Some Java 8 versions on Unix only capture the seconds in lastModified, so we cut off the milliseconds returned from the filesystem as well.
// For example, Oracle JDK 1.8.0_181-b13 does not capture milliseconds, while OpenJDK 1.8.0_242-b08 does.
return (JavaVersion.current().java9Compatible || OperatingSystem.current().windows)
? lastModified
: lastModified.intdiv(1000) * 1000
Expand Down

0 comments on commit c478b9b

Please sign in to comment.