diff --git a/scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/FileOps.scala b/scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/FileOps.scala index 6719a83f6e..535ff11fee 100644 --- a/scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/FileOps.scala +++ b/scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/FileOps.scala @@ -11,17 +11,21 @@ import org.scalafmt.CompatCollections.JavaConverters._ object FileOps { - @inline - def getLastModifiedMsec(file: Path): Long = - Files.getLastModifiedTime(file, LinkOption.NOFOLLOW_LINKS).toMillis + def getLastModifiedMsec(file: Path): Long = { + val attributes = getAttributes(file) + val mtime = attributes.lastModifiedTime().toMillis + if (attributes.isSymbolicLink) + math.max(mtime, Files.getLastModifiedTime(file).toMillis) + else mtime + } @inline def isDirectory(file: Path): Boolean = - Files.isDirectory(file, LinkOption.NOFOLLOW_LINKS) + Files.isDirectory(file) @inline def isRegularFile(file: Path): Boolean = - Files.isRegularFile(file, LinkOption.NOFOLLOW_LINKS) + Files.isRegularFile(file) @inline def getAttributes(file: Path): BasicFileAttributes = @@ -31,6 +35,10 @@ object FileOps { LinkOption.NOFOLLOW_LINKS ) + @inline + def getAttributesFollowLinks(file: Path): BasicFileAttributes = + Files.readAttributes(file, classOf[BasicFileAttributes]) + def listFiles(path: String): Seq[Path] = listFiles(getFile(path))