From 2f81ca80930450cbbb12dba7abd112e7b296f1f6 Mon Sep 17 00:00:00 2001 From: Jacob Mitchell Date: Mon, 19 Sep 2016 22:34:11 -0700 Subject: 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. --- src/fileio.sml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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 -- cgit v1.2.3