2013-02-20 23:43:01 -05:00
|
|
|
package asink
|
2013-02-13 07:31:10 -05:00
|
|
|
|
2013-08-13 23:18:17 -04:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2013-02-13 07:31:10 -05:00
|
|
|
//event type
|
2013-02-11 23:16:19 -05:00
|
|
|
type EventType uint32
|
|
|
|
|
|
|
|
const (
|
2013-02-11 23:17:12 -05:00
|
|
|
UPDATE = 1 << iota
|
2013-02-11 23:16:19 -05:00
|
|
|
DELETE
|
|
|
|
)
|
|
|
|
|
2013-02-13 07:31:10 -05:00
|
|
|
//event status
|
|
|
|
type EventStatus uint32
|
|
|
|
|
|
|
|
const (
|
2013-08-14 07:26:52 -04:00
|
|
|
//Local event status flags
|
|
|
|
DISCARDED = 1 << iota //event is to be discarded because it errored or is duplicate
|
2013-02-13 07:31:10 -05:00
|
|
|
)
|
|
|
|
|
2013-02-11 23:16:19 -05:00
|
|
|
type Event struct {
|
2013-02-22 00:06:10 -05:00
|
|
|
Id int64
|
|
|
|
LocalId int64
|
|
|
|
Type EventType
|
|
|
|
Status EventStatus
|
|
|
|
Path string
|
|
|
|
Hash string
|
2013-08-13 20:43:16 -04:00
|
|
|
Predecessor string
|
2013-02-22 00:06:10 -05:00
|
|
|
Timestamp int64
|
2013-08-13 23:18:17 -04:00
|
|
|
Permissions os.FileMode
|
2013-02-22 00:06:10 -05:00
|
|
|
InDB bool `json:"-"` //defaults to false. Omitted from json marshalling.
|
2013-02-11 23:16:19 -05:00
|
|
|
}
|
|
|
|
|
2013-08-13 20:42:51 -04:00
|
|
|
func (e *Event) IsUpdate() bool {
|
2013-02-11 23:17:12 -05:00
|
|
|
return e.Type&UPDATE == UPDATE
|
2013-02-11 23:16:19 -05:00
|
|
|
}
|
|
|
|
|
2013-08-13 20:42:51 -04:00
|
|
|
func (e *Event) IsDelete() bool {
|
2013-02-11 23:17:12 -05:00
|
|
|
return e.Type&DELETE == DELETE
|
2013-02-11 23:16:19 -05:00
|
|
|
}
|
2013-08-13 20:43:16 -04:00
|
|
|
|
|
|
|
func (e *Event) IsSameEvent(e2 *Event) bool {
|
|
|
|
return (e.Type == e2.Type && e.Path == e2.Path && e.Hash == e2.Hash && e.Predecessor == e2.Predecessor && e.Timestamp == e2.Timestamp && e.Permissions == e2.Permissions)
|
|
|
|
}
|