mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
改进gfpool
This commit is contained in:
@ -87,13 +87,7 @@ func OpenWithFlag(path string, flag int) (*os.File, error) {
|
||||
// 判断所给路径文件/文件夹是否存在
|
||||
func Exists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return os.IsExist(err)
|
||||
}
|
||||
|
||||
// 判断所给路径是否为文件夹
|
||||
|
||||
@ -93,14 +93,11 @@ func (p *Pool) File() (*File, error) {
|
||||
f.Seek(0, 0)
|
||||
}
|
||||
if f.flag & os.O_CREATE > 0 {
|
||||
_, err := f.Stat()
|
||||
if err != nil {
|
||||
if !os.IsExist(err) {
|
||||
if file, err := os.OpenFile(f.path, f.flag, f.perm); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
f.File = *file
|
||||
}
|
||||
if _, err := os.Stat(f.path); os.IsNotExist(err) {
|
||||
if file, err := os.OpenFile(f.path, f.flag, f.perm); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
f.File = *file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
import (
|
||||
"gitee.com/johng/gf/g/os/glog"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glog.SetPath("/tmp/test-logs")
|
||||
for {
|
||||
glog.Println("1")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user