2017-02-07 21:33:23 +00:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build !plan9
|
|
|
|
|
|
|
|
// Package fsnotify provides a platform-independent interface for file system notifications.
|
|
|
|
package fsnotify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Event represents a single file system notification.
|
|
|
|
type Event struct {
|
|
|
|
Name string // Relative path to the file or directory.
|
|
|
|
Op Op // File operation that triggered the event.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Op describes a set of file operations.
|
|
|
|
type Op uint32
|
|
|
|
|
|
|
|
// These are the generalized file operations that can trigger a notification.
|
|
|
|
const (
|
|
|
|
Create Op = 1 << iota
|
|
|
|
Write
|
|
|
|
Remove
|
|
|
|
Rename
|
|
|
|
Chmod
|
|
|
|
)
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
func (op Op) String() string {
|
2017-02-07 21:33:23 +00:00
|
|
|
// Use a buffer for efficient string concatenation
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
if op&Create == Create {
|
2017-02-07 21:33:23 +00:00
|
|
|
buffer.WriteString("|CREATE")
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
if op&Remove == Remove {
|
2017-02-07 21:33:23 +00:00
|
|
|
buffer.WriteString("|REMOVE")
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
if op&Write == Write {
|
2017-02-07 21:33:23 +00:00
|
|
|
buffer.WriteString("|WRITE")
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
if op&Rename == Rename {
|
2017-02-07 21:33:23 +00:00
|
|
|
buffer.WriteString("|RENAME")
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
if op&Chmod == Chmod {
|
2017-02-07 21:33:23 +00:00
|
|
|
buffer.WriteString("|CHMOD")
|
|
|
|
}
|
|
|
|
if buffer.Len() == 0 {
|
2017-04-11 15:10:46 +00:00
|
|
|
return ""
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
return buffer.String()[1:] // Strip leading pipe
|
|
|
|
}
|
2017-02-07 21:33:23 +00:00
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
// String returns a string representation of the event in the form
|
|
|
|
// "file: REMOVE|WRITE|..."
|
|
|
|
func (e Event) String() string {
|
|
|
|
return fmt.Sprintf("%q: %s", e.Name, e.Op.String())
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|