summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jacob Mitchell <jmitchell@member.fsf.org>2016-09-19 22:34:11 -0700
committerGravatar Jacob Mitchell <jmitchell@member.fsf.org>2016-09-19 22:34:11 -0700
commit2f81ca80930450cbbb12dba7abd112e7b296f1f6 (patch)
treec32d4e40b99242c7eba2ae198639611753425240
parent3afe16344c02881e4ace9e8965f48154b5225638 (diff)
Use 1s precision when comparing file mtimes
HTTP Last-Modified caching depends on mtimes of files read during compilation. Only mtimes before the compiler's start (reset) time are considered. On filesystems with lower mtime precision than Standard ML's Time.now, a temporary file generated by the compiler may have an mtime preceding the reset time even though it was modified after. The fix here is to compare times using 1s precision, the most granular used by filesystems.
-rw-r--r--src/fileio.sml11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/fileio.sml b/src/fileio.sml
index 72e72f6d..cab9d8a3 100644
--- a/src/fileio.sml
+++ b/src/fileio.sml
@@ -3,9 +3,14 @@ structure FileIO :> FILE_IO = struct
val mostRecentModTimeRef = ref (Time.zeroTime)
fun checkFileModTime fname =
- let val mtime = OS.FileSys.modTime fname in
- if Time.compare (mtime, !mostRecentModTimeRef) = GREATER andalso
- Time.compare (mtime, Globals.getResetTime ()) = LESS
+ let
+ val mtime = OS.FileSys.modTime fname
+ val mostRecentMod = !mostRecentModTimeRef
+ val resetTime = Globals.getResetTime ()
+ fun lessThan (a, b) = LargeInt.compare (Time.toSeconds a, Time.toSeconds b) = LESS
+ infix lessThan
+ in
+ if mostRecentMod lessThan mtime andalso mtime lessThan resetTime
then mostRecentModTimeRef := mtime
else ()
end