github.com/Hellyna/notify@v0.0.0-20210101060149-8ebdd4ef22cf/event_inotify.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 linux
     6  
     7  package notify
     8  
     9  import "golang.org/x/sys/unix"
    10  
    11  // Platform independent event values.
    12  const (
    13  	osSpecificCreate Event = 0x100000 << iota
    14  	osSpecificRemove
    15  	osSpecificWrite
    16  	osSpecificRename
    17  	// internal
    18  	// recursive is used to distinguish recursive eventsets from non-recursive ones
    19  	recursive
    20  	// omit is used for dispatching internal events; only those events are sent
    21  	// for which both the event and the watchpoint has omit in theirs event sets.
    22  	omit
    23  )
    24  
    25  // Inotify specific masks are legal, implemented events that are guaranteed to
    26  // work with notify package on linux-based systems.
    27  const (
    28  	InAccess       = Event(unix.IN_ACCESS)        // File was accessed
    29  	InModify       = Event(unix.IN_MODIFY)        // File was modified
    30  	InAttrib       = Event(unix.IN_ATTRIB)        // Metadata changed
    31  	InCloseWrite   = Event(unix.IN_CLOSE_WRITE)   // Writtable file was closed
    32  	InCloseNowrite = Event(unix.IN_CLOSE_NOWRITE) // Unwrittable file closed
    33  	InOpen         = Event(unix.IN_OPEN)          // File was opened
    34  	InMovedFrom    = Event(unix.IN_MOVED_FROM)    // File was moved from X
    35  	InMovedTo      = Event(unix.IN_MOVED_TO)      // File was moved to Y
    36  	InCreate       = Event(unix.IN_CREATE)        // Subfile was created
    37  	InDelete       = Event(unix.IN_DELETE)        // Subfile was deleted
    38  	InDeleteSelf   = Event(unix.IN_DELETE_SELF)   // Self was deleted
    39  	InMoveSelf     = Event(unix.IN_MOVE_SELF)     // Self was moved
    40  )
    41  
    42  var osestr = map[Event]string{
    43  	InAccess:       "notify.InAccess",
    44  	InModify:       "notify.InModify",
    45  	InAttrib:       "notify.InAttrib",
    46  	InCloseWrite:   "notify.InCloseWrite",
    47  	InCloseNowrite: "notify.InCloseNowrite",
    48  	InOpen:         "notify.InOpen",
    49  	InMovedFrom:    "notify.InMovedFrom",
    50  	InMovedTo:      "notify.InMovedTo",
    51  	InCreate:       "notify.InCreate",
    52  	InDelete:       "notify.InDelete",
    53  	InDeleteSelf:   "notify.InDeleteSelf",
    54  	InMoveSelf:     "notify.InMoveSelf",
    55  }
    56  
    57  // Inotify behavior events are not **currently** supported by notify package.
    58  const (
    59  	inDontFollow = Event(unix.IN_DONT_FOLLOW)
    60  	inExclUnlink = Event(unix.IN_EXCL_UNLINK)
    61  	inMaskAdd    = Event(unix.IN_MASK_ADD)
    62  	inOneshot    = Event(unix.IN_ONESHOT)
    63  	inOnlydir    = Event(unix.IN_ONLYDIR)
    64  )
    65  
    66  type event struct {
    67  	sys   unix.InotifyEvent
    68  	path  string
    69  	event Event
    70  }
    71  
    72  func (e *event) Event() Event         { return e.event }
    73  func (e *event) Path() string         { return e.path }
    74  func (e *event) Sys() interface{}     { return &e.sys }
    75  func (e *event) isDir() (bool, error) { return e.sys.Mask&unix.IN_ISDIR != 0, nil }