-
Notifications
You must be signed in to change notification settings - Fork 31
/
fileEvent.go
59 lines (53 loc) · 1.31 KB
/
fileEvent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package watcher
import "fmt"
//"log"
const (
// NONE means no event, initial state.
NONE = iota
// CREATED means file was created.
CREATED
// DELETED means file was deleted.
DELETED
// MODIFIED means file was modified.
MODIFIED
// PERM means changed permissions
PERM
// NOEXIST means file does not exist.
NOEXIST
// NOPERM means no permissions for the file (see const block comment).
NOPERM
// INVALID means any type of error not represented above.
INVALID
)
// FileEvent is a wrapper around github.com/howeyc/fsnotify.FileEvent
type FileEvent struct {
Event int
Path string
UnixNano int64
}
// newFileEvent creates a new file event.
func newFileEvent(op int, path string, unixNano int64) *FileEvent {
//log.Printf("to channel %+v\n", originEvent)
return &FileEvent{Event: op, Path: path, UnixNano: unixNano}
}
// String returns an eye friendly version of this event.
func (fe *FileEvent) String() string {
var status string
switch fe.Event {
case CREATED:
status = "was created"
case DELETED:
status = "was deleted"
case MODIFIED:
status = "was modified"
case PERM:
status = "permissions changed"
case NOEXIST:
status = "does not exist"
case NOPERM:
status = "is not accessible (permission)"
case INVALID:
status = "is invalid"
}
return fmt.Sprintf("%s %s", fe.Path, status)
}