aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/fileio.sml
diff options
context:
space:
mode:
authorGravatar Jacob Mitchell <jmitchell@member.fsf.org>2016-09-07 13:19:13 -0700
committerGravatar Jacob Mitchell <jmitchell@member.fsf.org>2016-09-07 13:19:13 -0700
commit51ac19f565fa935eec6d9dd1f7119c6227383a3c (patch)
tree9539e4a61dd38f2e65d78a5805b3eadef26cfebf /src/fileio.sml
parentc49ad46cc190e63f2395fcef03deff4386845877 (diff)
HTTP Last-Modified: latest modtime of source files
See issue #38.
Diffstat (limited to 'src/fileio.sml')
-rw-r--r--src/fileio.sml34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/fileio.sml b/src/fileio.sml
new file mode 100644
index 00000000..72e72f6d
--- /dev/null
+++ b/src/fileio.sml
@@ -0,0 +1,34 @@
+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
+ then mostRecentModTimeRef := mtime
+ else ()
+ end
+
+fun mostRecentModTime () =
+ if Time.compare (!mostRecentModTimeRef, Time.zeroTime) = EQUAL
+ then Globals.getResetTime ()
+ else !mostRecentModTimeRef
+
+fun txtOpenIn fname =
+ let
+ val inf = TextIO.openIn fname
+ val () = checkFileModTime fname
+ in
+ inf
+ end
+
+fun binOpenIn fname =
+ let
+ val inf = BinIO.openIn fname
+ val () = checkFileModTime fname
+ in
+ inf
+ end
+
+end