mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 04:06:39 +00:00
0884f89431
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
// 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.
|
|
|
|
//go:build !plan9
|
|
// +build !plan9
|
|
|
|
// Package fsnotify provides a platform-independent interface for file system notifications.
|
|
package fsnotify
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"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
|
|
)
|
|
|
|
func (op Op) String() string {
|
|
// Use a buffer for efficient string concatenation
|
|
var buffer bytes.Buffer
|
|
|
|
if op&Create == Create {
|
|
buffer.WriteString("|CREATE")
|
|
}
|
|
if op&Remove == Remove {
|
|
buffer.WriteString("|REMOVE")
|
|
}
|
|
if op&Write == Write {
|
|
buffer.WriteString("|WRITE")
|
|
}
|
|
if op&Rename == Rename {
|
|
buffer.WriteString("|RENAME")
|
|
}
|
|
if op&Chmod == Chmod {
|
|
buffer.WriteString("|CHMOD")
|
|
}
|
|
if buffer.Len() == 0 {
|
|
return ""
|
|
}
|
|
return buffer.String()[1:] // Strip leading pipe
|
|
}
|
|
|
|
// 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())
|
|
}
|
|
|
|
// Common errors that can be reported by a watcher
|
|
var (
|
|
ErrEventOverflow = errors.New("fsnotify queue overflow")
|
|
)
|