mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
改进gfpool
This commit is contained in:
@ -86,8 +86,10 @@ func OpenWithFlag(path string, flag int) (*os.File, error) {
|
||||
|
||||
// 判断所给路径文件/文件夹是否存在
|
||||
func Exists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return os.IsExist(err)
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 判断所给路径是否为文件夹
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/container/gmap"
|
||||
"gitee.com/johng/gf/g/os/gfsnotify"
|
||||
"gitee.com/johng/gf/g/os/glog"
|
||||
)
|
||||
|
||||
// 文件目录搜索管理对象
|
||||
@ -41,12 +42,15 @@ func (sp *SPath) Set(path string) error {
|
||||
}
|
||||
}
|
||||
if r != "" && gfile.IsDir(r) {
|
||||
r = strings.TrimRight(r, gfile.Separator)
|
||||
sp.mu.Lock()
|
||||
sp.paths = []string{strings.TrimRight(r, gfile.Separator)}
|
||||
sp.paths = []string{r}
|
||||
sp.mu.Unlock()
|
||||
sp.cache.Clear()
|
||||
glog.Debug("gspath.SetPath: ", r)
|
||||
return nil
|
||||
}
|
||||
glog.Debug("gspath.SetPath failed: ", path)
|
||||
return errors.New("invalid path:" + path)
|
||||
}
|
||||
|
||||
@ -60,11 +64,14 @@ func (sp *SPath) Add(path string) error {
|
||||
}
|
||||
}
|
||||
if r != "" && gfile.IsDir(r) {
|
||||
r = strings.TrimRight(r, gfile.Separator)
|
||||
sp.mu.Lock()
|
||||
sp.paths = append(sp.paths, r)
|
||||
sp.mu.Unlock()
|
||||
glog.Debug("gspath.Add: ", r)
|
||||
return nil
|
||||
}
|
||||
glog.Debug("gspath.Add failed: ", path)
|
||||
return errors.New("invalid path:" + path)
|
||||
}
|
||||
|
||||
@ -100,6 +107,7 @@ func (sp *SPath) Size() int {
|
||||
// 添加文件监控,当文件删除时,同时也删除搜索结果缓存
|
||||
func (sp *SPath) addMonitor(name, path string) {
|
||||
gfsnotify.Add(path, func(event *gfsnotify.Event) {
|
||||
glog.Debug("gspath.monitor:", event)
|
||||
if event.IsRemove() {
|
||||
sp.cache.Remove(name)
|
||||
}
|
||||
|
||||
@ -3,9 +3,13 @@ package main
|
||||
import (
|
||||
"gitee.com/johng/gf/g/os/glog"
|
||||
"time"
|
||||
"gitee.com/johng/gf/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
g.Config().AddPath("eeee")
|
||||
g.Config().AddPath(".")
|
||||
glog.SetPath(g.Config().GetString("logPath"))
|
||||
glog.SetPath("/tmp/test-logs")
|
||||
for {
|
||||
glog.Println("1")
|
||||
|
||||
Reference in New Issue
Block a user