diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-17 03:39:54 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-17 03:41:38 -0400 |
commit | ac2e2c0e7800ebbd6ca8087e546fb9d3480cb57e (patch) | |
tree | b4c745228bfdc5bdb5cb1d208471dc5ac49bdad3 /stage1 | |
parent | 9dbe839f074a8ed69f1e2853f7d40c21a9db407f (diff) | |
download | cbt-ac2e2c0e7800ebbd6ca8087e546fb9d3480cb57e.tar.gz cbt-ac2e2c0e7800ebbd6ca8087e546fb9d3480cb57e.tar.bz2 cbt-ac2e2c0e7800ebbd6ca8087e546fb9d3480cb57e.zip |
add helper for caching based on a status file
Diffstat (limited to 'stage1')
-rw-r--r-- | stage1/Stage1Lib.scala | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 7f7fa37..f66eff4 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -482,6 +482,21 @@ ${sourceFiles.sorted.mkString(" \\\n")} StandardOpenOption.APPEND ) } + def cached[T]( targetDirectory: File, inputLastModified: Long )( action: () => T ): (Option[T],Long) = { + val t = targetDirectory + val start = System.currentTimeMillis + def lastSucceeded = t.lastModified + def outputLastModified = t.listRecursive.diff(t :: Nil).map(_.lastModified).maxOption.getOrElse(0l) + def updateSucceeded(time: Long) = Files.setLastModifiedTime( t.toPath, FileTime.fromMillis(time) ) + ( + ( inputLastModified >= lastSucceeded ).option{ + val result: T = action() + updateSucceeded( start ) + result + }, + outputLastModified + ) + } } import scala.reflect._ |