github.com/FabianKramm/notify@v0.9.3-0.20210719135015-4705c29227a1/watchpoint_readdcw.go (about)

     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.
     4  
     5  // +build windows
     6  
     7  package notify
     8  
     9  // eventmask uses ei to create a new event which contains internal flags used by
    10  // notify package logic. If one of FileAction* masks is detected, this function
    11  // adds corresponding FileNotifyChange* values. This allows non registered
    12  // FileAction* events to be passed on.
    13  func eventmask(ei EventInfo, extra Event) (e Event) {
    14  	if e = ei.Event() | extra; e&fileActionAll != 0 {
    15  		if ev, ok := ei.(*event); ok {
    16  			switch ev.ftype {
    17  			case fTypeFile:
    18  				e |= FileNotifyChangeFileName
    19  			case fTypeDirectory:
    20  				e |= FileNotifyChangeDirName
    21  			case fTypeUnknown:
    22  				e |= fileNotifyChangeModified
    23  			}
    24  			return e &^ fileActionAll
    25  		}
    26  	}
    27  	return
    28  }
    29  
    30  // matches reports a match only when:
    31  //
    32  //   - for user events, when event is present in the given set
    33  //   - for internal events, when additionally both event and set have omit bit set
    34  //
    35  // Internal events must not be sent to user channels and vice versa.
    36  func matches(set, event Event) bool {
    37  	return (set&omit)^(event&omit) == 0 && (set&event == event || set&fileNotifyChangeModified&event != 0)
    38  }