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