Don't ever use UNIX file modification time for event modification time

Doing so can cause inconsistency and cause events to get dropped that
shouldn't. Also add warning to local event side if an event is reported
by the watcher that is not more recent than the event which was
previously the latest local event.
This commit is contained in:
Aaron Lindsay 2013-09-08 22:51:36 -04:00
parent d7cd6f348c
commit 1b4104a928
2 changed files with 7 additions and 1 deletions

View File

@ -141,6 +141,12 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
defer UnlockPath(event) defer UnlockPath(event)
if latestLocal != nil { if latestLocal != nil {
event.Predecessor = latestLocal.Hash event.Predecessor = latestLocal.Hash
if event.Timestamp < latestLocal.Timestamp {
fmt.Printf("trying to send event older than latestLocal:\n")
fmt.Printf("OLD %+v\n", latestLocal)
fmt.Printf("NEW %+v\n", event)
}
} }
if event.IsUpdate() { if event.IsUpdate() {

View File

@ -29,7 +29,7 @@ func StartWatching(watchDir string, fileUpdates chan *asink.Event) {
event := new(asink.Event) event := new(asink.Event)
event.Path = path event.Path = path
event.Type = asink.UPDATE event.Type = asink.UPDATE
event.Timestamp = info.ModTime().UnixNano() event.Timestamp = time.Now().UnixNano()
fileUpdates <- event fileUpdates <- event
} }
return nil return nil