1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
15 // Platform independent event values.
17 osSpecificCreate Event = 1 << (20 + iota)
21 // recursive is used to distinguish recursive eventsets from non-recursive ones
23 // omit is used for dispatching internal events; only those events are sent
24 // for which both the event and the watchpoint has omit in theirs event sets.
26 // dirmarker TODO(pknap)
30 // ReadDirectoryChangesW filters
31 // On Windows the following events can be passed to Watch. A different set of
32 // events (see actions below) are received on the channel passed to Watch.
33 // For more information refer to
34 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx
36 FileNotifyChangeFileName = Event(syscall.FILE_NOTIFY_CHANGE_FILE_NAME)
37 FileNotifyChangeDirName = Event(syscall.FILE_NOTIFY_CHANGE_DIR_NAME)
38 FileNotifyChangeAttributes = Event(syscall.FILE_NOTIFY_CHANGE_ATTRIBUTES)
39 FileNotifyChangeSize = Event(syscall.FILE_NOTIFY_CHANGE_SIZE)
40 FileNotifyChangeLastWrite = Event(syscall.FILE_NOTIFY_CHANGE_LAST_WRITE)
41 FileNotifyChangeLastAccess = Event(syscall.FILE_NOTIFY_CHANGE_LAST_ACCESS)
42 FileNotifyChangeCreation = Event(syscall.FILE_NOTIFY_CHANGE_CREATION)
43 FileNotifyChangeSecurity = Event(syscallFileNotifyChangeSecurity)
47 fileNotifyChangeAll = 0x17f // logical sum of all FileNotifyChange* events.
48 fileNotifyChangeModified = fileNotifyChangeAll &^ (FileNotifyChangeFileName | FileNotifyChangeDirName)
51 // according to: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx
52 // this flag should be declared in: http://golang.org/src/pkg/syscall/ztypes_windows.go
53 const syscallFileNotifyChangeSecurity = 0x00000100
55 // ReadDirectoryChangesW actions
56 // The following events are returned on the channel passed to Watch, but cannot
57 // be passed to Watch itself (see filters above). You can find a table showing
58 // the relation between actions and filteres at
59 // https://github.com/rjeczalik/notify/issues/10#issuecomment-66179535
60 // The msdn documentation on actions is part of
61 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364391(v=vs.85).aspx
63 FileActionAdded = Event(syscall.FILE_ACTION_ADDED) << 12
64 FileActionRemoved = Event(syscall.FILE_ACTION_REMOVED) << 12
65 FileActionModified = Event(syscall.FILE_ACTION_MODIFIED) << 14
66 FileActionRenamedOldName = Event(syscall.FILE_ACTION_RENAMED_OLD_NAME) << 15
67 FileActionRenamedNewName = Event(syscall.FILE_ACTION_RENAMED_NEW_NAME) << 16
70 const fileActionAll = 0x7f000 // logical sum of all FileAction* events.
72 var osestr = map[Event]string{
73 FileNotifyChangeFileName: "notify.FileNotifyChangeFileName",
74 FileNotifyChangeDirName: "notify.FileNotifyChangeDirName",
75 FileNotifyChangeAttributes: "notify.FileNotifyChangeAttributes",
76 FileNotifyChangeSize: "notify.FileNotifyChangeSize",
77 FileNotifyChangeLastWrite: "notify.FileNotifyChangeLastWrite",
78 FileNotifyChangeLastAccess: "notify.FileNotifyChangeLastAccess",
79 FileNotifyChangeCreation: "notify.FileNotifyChangeCreation",
80 FileNotifyChangeSecurity: "notify.FileNotifyChangeSecurity",
82 FileActionAdded: "notify.FileActionAdded",
83 FileActionRemoved: "notify.FileActionRemoved",
84 FileActionModified: "notify.FileActionModified",
85 FileActionRenamedOldName: "notify.FileActionRenamedOldName",
86 FileActionRenamedNewName: "notify.FileActionRenamedNewName",
90 fTypeUnknown uint8 = iota
95 // TODO(ppknap) : doc.
105 func (e *event) Event() Event { return e.e }
106 func (e *event) Path() string { return filepath.Join(syscall.UTF16ToString(e.pathw), e.name) }
107 func (e *event) Sys() interface{} { return e.ftype }
109 func (e *event) isDir() (bool, error) {
110 if e.ftype != fTypeUnknown {
111 return e.ftype == fTypeDirectory, nil
113 fi, err := os.Stat(e.Path())
117 return fi.IsDir(), nil