1 Star 0 Fork 0

micro-tools/wf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gfpool_file.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-09-27 22:16 +08:00 . 升级go-ole
package gfpool
import (
"errors"
"fmt"
"os"
"time"
)
// Open creates and returns a file item with given file path, flag and opening permission.
// It automatically creates an associated file pointer pool internally when it's called first time.
// It retrieves a file item from the file pointer pool after then.
func Open(path string, flag int, perm os.FileMode, ttl ...time.Duration) (file *File, err error) {
var fpTTL time.Duration
if len(ttl) > 0 {
fpTTL = ttl[0]
}
// DO NOT search the path here wasting performance!
// Leave following codes just for warning you.
//
//path, err = gfile.Search(path)
//if err != nil {
// return nil, err
//}
pool := pools.GetOrSetFuncLock(
fmt.Sprintf("%s&%d&%d&%d", path, flag, fpTTL, perm),
func() interface{} {
return New(path, flag, perm, fpTTL)
},
).(*Pool)
return pool.File()
}
// Stat returns the FileInfo structure describing file.
func (f *File) Stat() (os.FileInfo, error) {
if f.stat == nil {
return nil, errors.New("file stat is empty")
}
return f.stat, nil
}
// Close puts the file pointer back to the file pointer pool.
func (f *File) Close() error {
if f.pid == f.pool.id.Val() {
return f.pool.pool.Put(f)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/micro-tools/wf.git
git@gitee.com:micro-tools/wf.git
micro-tools
wf
wf
v1.0.2

搜索帮助