Triggered Execution should be aware of rename or move file

This commit is contained in:
xuwei-k 2014-06-08 03:15:45 +09:00
parent 47b5790c41
commit dd628d2441
1 changed files with 18 additions and 8 deletions

View File

@ -10,13 +10,14 @@ object SourceModificationWatch {
{
import state._
def sourceFiles: Iterable[java.io.File] = sourcesFinder.get
val (lastModifiedTime, fileCount) =
((0L, 0) /: sourceFiles) { (acc, file) => (math.max(acc._1, file.lastModified), acc._2 + 1) }
val sourceFiles: Iterable[java.io.File] = sourcesFinder.get
val sourceFilesPath: Set[String] = sourceFiles.map(_.getCanonicalPath)(collection.breakOut)
val lastModifiedTime =
(0L /: sourceFiles) { (acc, file) => math.max(acc, file.lastModified) }
val sourcesModified =
lastModifiedTime > lastCallbackCallTime ||
previousFileCount != fileCount
previousFiles != sourceFilesPath
val (triggered, newCallbackCallTime) =
if (sourcesModified)
@ -24,7 +25,7 @@ object SourceModificationWatch {
else
(awaitingQuietPeriod, lastCallbackCallTime)
val newState = new WatchState(newCallbackCallTime, fileCount, sourcesModified, if (triggered) count + 1 else count)
val newState = new WatchState(newCallbackCallTime, sourceFilesPath, sourcesModified, if (triggered) count + 1 else count)
if (triggered)
(true, newState)
else {
@ -36,7 +37,16 @@ object SourceModificationWatch {
}
}
}
final class WatchState(val lastCallbackCallTime: Long, val previousFileCount: Int, val awaitingQuietPeriod: Boolean, val count: Int)
final class WatchState(val lastCallbackCallTime: Long, val previousFiles: Set[String], val awaitingQuietPeriod: Boolean, val count: Int) {
def previousFileCount: Int = previousFiles.size
@deprecated("Use another constructor", "0.13.6")
def this(lastCallbackCallTime: Long, previousFileCount: Int, awaitingQuietPeriod: Boolean, count: Int) {
this(lastCallbackCallTime, Set.empty[String], awaitingQuietPeriod, count)
}
}
object WatchState {
def empty = new WatchState(0L, 0, false, 0)
}
def empty = new WatchState(0L, Set.empty[String], false, 0)
}