From 5b87f505b0f63cbf60dfd97b7e4d06a414caafa9 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sat, 6 Aug 2022 19:56:40 +0200 Subject: [PATCH] windows: simplify a bit (#493) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The sys* constants were used in the old golang.org/x/exp/winfsnotify package on which this is based, but haven't been in use for a long time. Remove the "one shot", "dir only", and "ignore" options as they were never set. Also don't send "sysFSQOVERFLOW" as an event if the buffer is too long; we already send an error and it's just a weird magical number you get. This could be simplified greatly more by removing the whole sysFS… → windows.FILE_NOTIFY… → sysFS… conversions, but that's for another day. --- windows.go | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/windows.go b/windows.go index 17ada31..9b43d38 100644 --- a/windows.go +++ b/windows.go @@ -151,16 +151,11 @@ func (w *Watcher) WatchList() []string { // add various options to the watch. This has long since been removed. // // The "sys" in the name is misleading as they're not part of any "system". +// +// This should all be removed at some point, and just use windows.FILE_NOTIFY_* const ( - // Options for AddWatch - sysFSONESHOT = 0x80000000 - sysFSONLYDIR = 0x1000000 - - // Events - sysFSACCESS = 0x1 sysFSALLEVENTS = 0xfff sysFSATTRIB = 0x4 - sysFSCLOSE = 0x18 sysFSCREATE = 0x100 sysFSDELETE = 0x200 sysFSDELETESELF = 0x400 @@ -169,10 +164,7 @@ const ( sysFSMOVEDFROM = 0x40 sysFSMOVEDTO = 0x80 sysFSMOVESELF = 0x800 - - // Special events - sysFSIGNORED = 0x8000 - sysFSQOVERFLOW = 0x4000 + sysFSIGNORED = 0x8000 ) func (w *Watcher) newEvent(name string, mask uint32) Event { @@ -302,9 +294,6 @@ func (w *Watcher) addWatch(pathname string, flags uint64) error { if err != nil { return err } - if flags&sysFSONLYDIR != 0 && pathname != dir { - return nil - } ino, err := w.getIno(dir) if err != nil { @@ -427,11 +416,7 @@ func (w *Watcher) startRead(watch *watch) error { err := os.NewSyscallError("ReadDirectoryChanges", rdErr) if rdErr == windows.ERROR_ACCESS_DENIED && watch.mask&provisional == 0 { // Watched directory was probably removed - if w.sendEvent(watch.path, watch.mask&sysFSDELETESELF) { - if watch.mask&sysFSONESHOT != 0 { - watch.mask = 0 - } - } + w.sendEvent(watch.path, watch.mask&sysFSDELETESELF) err = nil } w.deleteWatch(watch) @@ -522,7 +507,6 @@ func (w *Watcher) readEvents() { var offset uint32 for { if n == 0 { - w.Events <- w.newEvent("", sysFSQOVERFLOW) w.sendError(errors.New("short read in readEvents()")) break } @@ -570,11 +554,7 @@ func (w *Watcher) readEvents() { } sendNameEvent := func() { - if w.sendEvent(fullname, watch.names[name]&mask) { - if watch.names[name]&sysFSONESHOT != 0 { - delete(watch.names, name) - } - } + w.sendEvent(fullname, watch.names[name]&mask) } if raw.Action != windows.FILE_ACTION_RENAMED_NEW_NAME { sendNameEvent() @@ -583,11 +563,8 @@ func (w *Watcher) readEvents() { w.sendEvent(fullname, watch.names[name]&sysFSIGNORED) delete(watch.names, name) } - if w.sendEvent(fullname, watch.mask&w.toFSnotifyFlags(raw.Action)) { - if watch.mask&sysFSONESHOT != 0 { - watch.mask = 0 - } - } + + w.sendEvent(fullname, watch.mask&w.toFSnotifyFlags(raw.Action)) if raw.Action == windows.FILE_ACTION_RENAMED_NEW_NAME { fullname = filepath.Join(watch.path, watch.rename) sendNameEvent() @@ -615,9 +592,6 @@ func (w *Watcher) readEvents() { func (w *Watcher) toWindowsFlags(mask uint64) uint32 { var m uint32 - if mask&sysFSACCESS != 0 { - m |= windows.FILE_NOTIFY_CHANGE_LAST_ACCESS - } if mask&sysFSMODIFY != 0 { m |= windows.FILE_NOTIFY_CHANGE_LAST_WRITE } -- 2.50.1