OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / github.com / fsnotify / fsnotify / fsnotify.go
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // +build !plan9
6
7 // Package fsnotify provides a platform-independent interface for file system notifications.
8 package fsnotify
9
10 import (
11         "bytes"
12         "errors"
13         "fmt"
14 )
15
16 // Event represents a single file system notification.
17 type Event struct {
18         Name string // Relative path to the file or directory.
19         Op   Op     // File operation that triggered the event.
20 }
21
22 // Op describes a set of file operations.
23 type Op uint32
24
25 // These are the generalized file operations that can trigger a notification.
26 const (
27         Create Op = 1 << iota
28         Write
29         Remove
30         Rename
31         Chmod
32 )
33
34 func (op Op) String() string {
35         // Use a buffer for efficient string concatenation
36         var buffer bytes.Buffer
37
38         if op&Create == Create {
39                 buffer.WriteString("|CREATE")
40         }
41         if op&Remove == Remove {
42                 buffer.WriteString("|REMOVE")
43         }
44         if op&Write == Write {
45                 buffer.WriteString("|WRITE")
46         }
47         if op&Rename == Rename {
48                 buffer.WriteString("|RENAME")
49         }
50         if op&Chmod == Chmod {
51                 buffer.WriteString("|CHMOD")
52         }
53         if buffer.Len() == 0 {
54                 return ""
55         }
56         return buffer.String()[1:] // Strip leading pipe
57 }
58
59 // String returns a string representation of the event in the form
60 // "file: REMOVE|WRITE|..."
61 func (e Event) String() string {
62         return fmt.Sprintf("%q: %s", e.Name, e.Op.String())
63 }
64
65 // Common errors that can be reported by a watcher
66 var ErrEventOverflow = errors.New("fsnotify queue overflow")