fsnotify

package
v0.0.0-...-b1e7d62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2014 License: BSD-3-Clause, Apache-2.0 Imports: 7 Imported by: 0

README

File system notifications for Go

Coverage GoDoc

Cross platform: Windows, Linux, BSD and OS X.

Adapter OS Status
inotify Linux, Android Supported
kqueue BSD, OS X, iOS Supported
ReadDirectoryChangesW Windows Supported
FSEvents OS X Planned
FEN Solaris 11 Planned
fanotify Linux 2.6.37+
Polling All
Plan 9

Please see the documentation for usage. The Wiki contains an FAQ and further information.

API stability

The fsnotify API has changed from what exists at github.com/howeyc/fsnotify (GoDoc).

Further changes are expected. You may use gopkg.in to lock to the current API:

import "gopkg.in/fsnotify.v0"

A new major revision will be tagged for any future API changes.

Contributing

A future version of Go will have fsnotify in the standard library, therefore fsnotify carries the same LICENSE as Go. Contributors retain their copyright, so we need you to fill out a short form before we can accept your contribution: Google Individual Contributor License Agreement.

Please read CONTRIBUTING before opening a pull request.

Example

See example_test.go.

Documentation

Overview

Package fsnotify implements file system notification.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Name string // Relative path to the file/directory.
	Op   Op     // Platform-independent bitmask.
}

Event represents a single file system event.

func (Event) String

func (e Event) String() string

String formats the event e in the form "filename: REMOVE|WRITE|..."

type Op

type Op uint32

Op describes a set of file operations.

const (
	Create Op = 1 << iota
	Write
	Remove
	Rename
	Chmod
)

These are the file operations that can trigger a notification.

type Watcher

type Watcher struct {
	Errors chan error // Errors are sent on this channel
	Events chan Event // Events are returned on this channel
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher creates and returns a new inotify instance using inotify_init(2)

Example
package main

import (
	"log"

	"github.com/go-fsnotify/fsnotify"
)

func main() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	go func() {
		for {
			select {
			case event := <-watcher.Events:
				log.Println("event:", event)
				if event.Op&fsnotify.Write == fsnotify.Write {
					log.Println("modified file:", event.Name)
				}
			case err := <-watcher.Errors:
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.Add("/tmp/foo")
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func (*Watcher) Add

func (w *Watcher) Add(name string) error

Add starts watching on the named file.

func (*Watcher) Close

func (w *Watcher) Close() error

Close closes an inotify watcher instance It sends a message to the reader goroutine to quit and removes all watches associated with the inotify instance

func (*Watcher) Remove

func (w *Watcher) Remove(name string) error

Remove stops watching on the named file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL