Add timestamp and status to Event type
This commit is contained in:
parent
5d3cd40195
commit
6975ef035c
19
events.go
19
events.go
@ -1,5 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//event type
|
||||||
type EventType uint32
|
type EventType uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -7,10 +12,24 @@ const (
|
|||||||
DELETE
|
DELETE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//event status
|
||||||
|
type EventStatus uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
NOTICED = 1 << iota //watcher.go has been notified that a file changed
|
||||||
|
COPIED_TO_TMP //temporary version saved off
|
||||||
|
HASHED //hash taken of tmp file
|
||||||
|
CACHED //tmp file renamed to its hash
|
||||||
|
UPLOADED //tmp file has been successfully uploaded to storage
|
||||||
|
ON_SERVER //server has been successfully notified of event
|
||||||
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type EventType
|
Type EventType
|
||||||
|
Status EventStatus
|
||||||
Path string
|
Path string
|
||||||
Hash string
|
Hash string
|
||||||
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Event) IsUpdate() bool {
|
func (e Event) IsUpdate() bool {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/howeyc/fsnotify"
|
"github.com/howeyc/fsnotify"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartWatching(watchDir string, fileUpdates chan *Event) {
|
func StartWatching(watchDir string, fileUpdates chan *Event) {
|
||||||
@ -45,7 +46,10 @@ func StartWatching(watchDir string, fileUpdates chan *Event) {
|
|||||||
panic("Unknown fsnotify event type")
|
panic("Unknown fsnotify event type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.Status = NOTICED
|
||||||
event.Path = ev.Name
|
event.Path = ev.Name
|
||||||
|
event.Timestamp = time.Now()
|
||||||
|
|
||||||
if event.IsUpdate() {
|
if event.IsUpdate() {
|
||||||
event.Hash, err = HashFile(ev.Name)
|
event.Hash, err = HashFile(ev.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user