mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
comment update for package gfsnotify
This commit is contained in:
@ -96,8 +96,8 @@ func New() (*Watcher, error) {
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Add monitors <path> using default watcher with callback function <callbackFunc>.
|
||||
// The optional parameter <recursive> specifies whether monitoring the <path> recursively, which is true in default.
|
||||
// Add monitors `path` using default watcher with callback function `callbackFunc`.
|
||||
// The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
|
||||
func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) {
|
||||
w, err := getDefaultWatcher()
|
||||
if err != nil {
|
||||
@ -106,11 +106,11 @@ func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callb
|
||||
return w.Add(path, callbackFunc, recursive...)
|
||||
}
|
||||
|
||||
// AddOnce monitors <path> using default watcher with callback function <callbackFunc> only once using unique name <name>.
|
||||
// If AddOnce is called multiple times with the same <name> parameter, <path> is only added to monitor once. It returns error
|
||||
// if it's called twice with the same <name>.
|
||||
// AddOnce monitors `path` using default watcher with callback function `callbackFunc` only once using unique name `name`.
|
||||
// If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once. It returns error
|
||||
// if it's called twice with the same `name`.
|
||||
//
|
||||
// The optional parameter <recursive> specifies whether monitoring the <path> recursively, which is true in default.
|
||||
// The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
|
||||
func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) {
|
||||
w, err := getDefaultWatcher()
|
||||
if err != nil {
|
||||
@ -119,7 +119,7 @@ func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bo
|
||||
return w.AddOnce(name, path, callbackFunc, recursive...)
|
||||
}
|
||||
|
||||
// Remove removes all monitoring callbacks of given <path> from watcher recursively.
|
||||
// Remove removes all monitoring callbacks of given `path` from watcher recursively.
|
||||
func Remove(path string) error {
|
||||
w, err := getDefaultWatcher()
|
||||
if err != nil {
|
||||
|
||||
@ -24,7 +24,7 @@ func fileDir(path string) string {
|
||||
return filepath.Dir(path)
|
||||
}
|
||||
|
||||
// fileRealPath converts the given <path> to its absolute path
|
||||
// fileRealPath converts the given `path` to its absolute path
|
||||
// and checks if the file path exists.
|
||||
// If the file does not exist, return an empty string.
|
||||
func fileRealPath(path string) string {
|
||||
@ -38,7 +38,7 @@ func fileRealPath(path string) string {
|
||||
return p
|
||||
}
|
||||
|
||||
// fileExists checks whether given <path> exist.
|
||||
// fileExists checks whether given `path` exist.
|
||||
func fileExists(path string) bool {
|
||||
if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) {
|
||||
return true
|
||||
@ -46,7 +46,7 @@ func fileExists(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// fileIsDir checks whether given <path> a directory.
|
||||
// fileIsDir checks whether given `path` a directory.
|
||||
func fileIsDir(path string) bool {
|
||||
s, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@ -55,7 +55,7 @@ func fileIsDir(path string) bool {
|
||||
return s.IsDir()
|
||||
}
|
||||
|
||||
// fileAllDirs returns all sub-folders including itself of given <path> recursively.
|
||||
// fileAllDirs returns all sub-folders including itself of given `path` recursively.
|
||||
func fileAllDirs(path string) (list []string) {
|
||||
list = []string{path}
|
||||
file, err := os.Open(path)
|
||||
@ -78,8 +78,8 @@ func fileAllDirs(path string) (list []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// fileScanDir returns all sub-files with absolute paths of given <path>,
|
||||
// It scans directory recursively if given parameter <recursive> is true.
|
||||
// fileScanDir returns all sub-files with absolute paths of given `path`,
|
||||
// It scans directory recursively if given parameter `recursive` is true.
|
||||
func fileScanDir(path string, pattern string, recursive ...bool) ([]string, error) {
|
||||
list, err := doFileScanDir(path, pattern, recursive...)
|
||||
if err != nil {
|
||||
@ -94,10 +94,10 @@ func fileScanDir(path string, pattern string, recursive ...bool) ([]string, erro
|
||||
// doFileScanDir is an internal method which scans directory
|
||||
// and returns the absolute path list of files that are not sorted.
|
||||
//
|
||||
// The pattern parameter <pattern> supports multiple file name patterns,
|
||||
// The pattern parameter `pattern` supports multiple file name patterns,
|
||||
// using the ',' symbol to separate multiple patterns.
|
||||
//
|
||||
// It scans directory recursively if given parameter <recursive> is true.
|
||||
// It scans directory recursively if given parameter `recursive` is true.
|
||||
func doFileScanDir(path string, pattern string, recursive ...bool) ([]string, error) {
|
||||
list := ([]string)(nil)
|
||||
file, err := os.Open(path)
|
||||
|
||||
@ -14,19 +14,20 @@ import (
|
||||
"github.com/gogf/gf/container/glist"
|
||||
)
|
||||
|
||||
// Add monitors <path> with callback function <callbackFunc> to the watcher.
|
||||
// The optional parameter <recursive> specifies whether monitoring the <path> recursively,
|
||||
// Add monitors `path` with callback function `callbackFunc` to the watcher.
|
||||
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
|
||||
// which is true in default.
|
||||
func (w *Watcher) Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) {
|
||||
return w.AddOnce("", path, callbackFunc, recursive...)
|
||||
}
|
||||
|
||||
// AddOnce monitors <path> with callback function <callbackFunc> only once using unique name
|
||||
// <name> to the watcher. If AddOnce is called multiple times with the same <name> parameter,
|
||||
// <path> is only added to monitor once.
|
||||
// It returns error if it's called twice with the same <name>.
|
||||
// AddOnce monitors `path` with callback function `callbackFunc` only once using unique name
|
||||
// `name` to the watcher. If AddOnce is called multiple times with the same `name` parameter,
|
||||
// `path` is only added to monitor once.
|
||||
//
|
||||
// The optional parameter <recursive> specifies whether monitoring the <path> recursively,
|
||||
// It returns error if it's called twice with the same `name`.
|
||||
//
|
||||
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
|
||||
// which is true in default.
|
||||
func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) {
|
||||
w.nameSet.AddIfNotExistFuncLock(name, func() bool {
|
||||
@ -99,8 +100,6 @@ func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event
|
||||
}
|
||||
// Add the callback to global callback map.
|
||||
callbackIdMap.Set(callback.Id, callback)
|
||||
|
||||
//intlog.Print("addWithCallbackFunc", name, path, callback.recursive)
|
||||
return
|
||||
}
|
||||
|
||||
@ -113,7 +112,7 @@ func (w *Watcher) Close() {
|
||||
close(w.closeChan)
|
||||
}
|
||||
|
||||
// Remove removes monitor and all callbacks associated with the <path> recursively.
|
||||
// Remove removes monitor and all callbacks associated with the `path` recursively.
|
||||
func (w *Watcher) Remove(path string) error {
|
||||
// Firstly remove the callbacks of the path.
|
||||
if r := w.callbacks.Remove(path); r != nil {
|
||||
|
||||
@ -134,7 +134,7 @@ func (w *Watcher) eventLoop() {
|
||||
}()
|
||||
}
|
||||
|
||||
// getCallbacks searches and returns all callbacks with given <path>.
|
||||
// getCallbacks searches and returns all callbacks with given `path`.
|
||||
// It also searches its parents for callbacks if they're recursive.
|
||||
func (w *Watcher) getCallbacks(path string) (callbacks []*Callback) {
|
||||
// Firstly add the callbacks of itself.
|
||||
|
||||
Reference in New Issue
Block a user