-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework Event to have platform-specific event types
- Loading branch information
Showing
7 changed files
with
142 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package notify | ||
|
||
import "strings" | ||
|
||
// Event TODO | ||
type Event int | ||
|
||
// String implements fmt.Stringer interface. | ||
func (e Event) String() string { | ||
var s []string | ||
for ev, str := range estr { | ||
if e&ev == ev { | ||
s = append(s, str) | ||
} | ||
} | ||
return strings.Join(s, "|") | ||
} | ||
|
||
// EventInfo TODO | ||
type EventInfo interface { | ||
Event() Event // TODO | ||
IsDir() bool // TODO | ||
Name() string // TODO | ||
Sys() interface{} // TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// +build linux | ||
|
||
package notify | ||
|
||
import "syscall" | ||
|
||
var ( | ||
Create = IN_CREATE | ||
Delete = IN_DELETE | ||
Write = IN_MODIFY | ||
Move = IN_MOVE | ||
) | ||
|
||
// All TODO | ||
var All = IN_ALL_EVENTS | ||
|
||
// Events TODO | ||
const ( | ||
IN_ACCESS = Event(syscall.IN_ACCESS) | ||
IN_MODIFY = Event(syscall.IN_MODIFY) | ||
IN_ATTRIB = Event(syscall.IN_ATTRIB) | ||
IN_CLOSE_WRITE = Event(syscall.IN_CLOSE_WRITE) | ||
IN_CLOSE_NOWRITE = Event(syscall.IN_CLOSE_NOWRITE) | ||
IN_OPEN = Event(syscall.IN_OPEN) | ||
IN_MOVED_FROM = Event(syscall.IN_MOVED_FROM) | ||
IN_MOVED_TO = Event(syscall.IN_MOVED_TO) | ||
IN_CREATE = Event(syscall.IN_CREATE) | ||
IN_DELETE = Event(syscall.IN_DELETE) | ||
IN_DELETE_SELF = Event(syscall.IN_DELETE_SELF) | ||
IN_MOVE_SELF = Event(syscall.IN_MOVE_SELF) | ||
IN_CLOSE = Event(syscall.IN_CLOSE) | ||
IN_MOVE = Event(syscall.IN_MOVE) | ||
IN_ALL_EVENTS = Event(syscall.IN_ALL_EVENTS) | ||
) | ||
|
||
var estr = map[Event]string{ | ||
Create: "create", | ||
Delete: "delete", | ||
Write: "write", | ||
Move: "move", | ||
IN_ACCESS: "syscall.IN_ACCESS", | ||
IN_MODIFY: "syscall.IN_MODIFY", | ||
IN_ATTRIB: "syscall.IN_ATTRIB", | ||
IN_CLOSE_WRITE: "syscall.IN_CLOSE_WRITE", | ||
IN_CLOSE_NOWRITE: "syscall.IN_CLOSE_NO_WRITE", | ||
IN_OPEN: "syscall.IN_OPEN", | ||
IN_MOVED_FROM: "syscall.IN_MOVED_FROM", | ||
IN_MOVED_TO: "syscall.IN_MOVED_TO", | ||
IN_CREATE: "syscall.IN_CREATE", | ||
IN_DELETE: "syscall.IN_DELETE", | ||
IN_DELETE_SELF: "syscall.IN_DELETE_SELF", | ||
IN_MOVE_SELF: "syscall.IN_MOVE_SELF", | ||
IN_CLOSE: "syscall.IN_CLOSE", | ||
IN_MOVE: "syscall.IN_MOVE", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// +build !linux | ||
|
||
package notify | ||
|
||
var ( | ||
Create = EV_STUB_CREATE | ||
Delete = EV_STUB_DELETE | ||
Write = EV_STUB_WRITE | ||
Move = EV_STUB_MOVE | ||
) | ||
|
||
// All TODO | ||
var All = EV_STUB_ALL | ||
|
||
// Events TODO | ||
const ( | ||
EV_STUB_CREATE = Event(0x00000001) | ||
EV_STUB_DELETE = Event(0x00000002) | ||
EV_STUB_WRITE = Event(0x00000004) | ||
EV_STUB_MOVE = Event(0x00000008) | ||
EV_STUB_ALL = Event(0x0000000f) | ||
) | ||
|
||
var estr = map[Event]string{ | ||
Create: "create", | ||
Delete: "delete", | ||
Write: "write", | ||
Move: "move", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package notify | ||
|
||
import "testing" | ||
|
||
func mock(m map[Event]string) func() { | ||
old := estr | ||
estr = m | ||
return func() { | ||
estr = old | ||
} | ||
} | ||
|
||
// This test is not safe to run in parallel with others. | ||
func TestEventString(t *testing.T) { | ||
m := map[Event]string{ | ||
0x01: "A", | ||
0x02: "B", | ||
0x04: "C", | ||
0x08: "D", | ||
0x0F: "E", | ||
} | ||
defer mock(m)() | ||
cases := map[Event]string{ | ||
0x01: "A", | ||
0x03: "A|B", | ||
0x07: "A|B|C", | ||
} | ||
for e, str := range cases { | ||
if s := e.String(); s != str { | ||
t.Errorf("want s=%s; got %s (e=%#x)", str, s, e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters