-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package notify | ||
|
||
import "strings" | ||
|
||
var estr = make(map[Event]string) | ||
|
||
// Event TODO | ||
type Event int | ||
|
||
// String implements fmt.Stringer interface. | ||
func (e Event) String() string { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
var s []string | ||
for i := uint(0); i < 32; i++ { | ||
This comment has been minimized.
Sorry, something went wrong.
rjeczalik
Author
Owner
|
||
if e := e & (1 << i); e != 0 { | ||
if str, ok := estr[e]; ok { | ||
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 | ||
} |
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) | ||
) | ||
|
||
func init() { | ||
estr[Create] = "create" | ||
estr[Delete] = "delete" | ||
estr[Write] = "write" | ||
estr[Move] = "move" | ||
estr[IN_ACCESS] = "syscall.IN_ACCESS" | ||
estr[IN_MODIFY] = "syscall.IN_MODIFY" | ||
estr[IN_ATTRIB] = "syscall.IN_ATTRIB" | ||
estr[IN_CLOSE_WRITE] = "syscall.IN_CLOSE_WRITE" | ||
estr[IN_CLOSE_NOWRITE] = "syscall.IN_CLOSE_NO_WRITE" | ||
estr[IN_OPEN] = "syscall.IN_OPEN" | ||
estr[IN_MOVED_FROM] = "syscall.IN_MOVED_FROM" | ||
estr[IN_MOVED_TO] = "syscall.IN_MOVED_TO" | ||
estr[IN_CREATE] = "syscall.IN_CREATE" | ||
estr[IN_DELETE] = "syscall.IN_DELETE" | ||
estr[IN_DELETE_SELF] = "syscall.IN_DELETE_SELF" | ||
estr[IN_MOVE_SELF] = "syscall.IN_MOVE_SELF" | ||
estr[IN_CLOSE] = "syscall.IN_CLOSE" | ||
estr[IN_MOVE] = "syscall.IN_MOVE" | ||
} |
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) | ||
) | ||
|
||
func init() { | ||
estr[Create] = "create" | ||
estr[Delete] = "delete" | ||
estr[Write] = "write" | ||
estr[Move] = "move" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package notify | ||
|
||
import "testing" | ||
|
||
func mock(m map[Event]string) (revert func()) { | ||
old := estr | ||
estr = m | ||
revert = func() { | ||
estr = old | ||
} | ||
return | ||
} | ||
|
||
// 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) | ||
} | ||
} | ||
} |
3 comments
on commit 0f94968
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ppknap say if it's ok to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather you used estr
map in that way:
var estr = map[Event]string{
Create: "create",
Delete: "delete",
//...
}
And you missed my second commit:P. However, you can freely merge this with wip. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I've reworked it, and second commit is #19.
With this impl
fmt.Println(Event(syscall.IN_MOVE_SELF, Move))
will printMove|syscall.IN_MOVE_SELF
.