1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
ruflin 提交于 2016-04-19 15:34 . Filebeat refactoring and cleanup
package input
import (
"os"
"github.com/elastic/beats/libbeat/logp"
)
const (
jsonErrorKey = "json_error"
)
type File struct {
File *os.File
FileInfo os.FileInfo
Path string
FileState *FileState
}
// NewFile create new File object
func NewFile(fileInfo os.FileInfo) File {
return File{
FileInfo: fileInfo,
}
}
// Check that the file isn't a symlink, mode is regular or file is nil
func (f *File) IsRegularFile() bool {
if f.File == nil {
logp.Critical("Harvester: BUG: f arg is nil")
return false
}
info, e := f.File.Stat()
if e != nil {
logp.Err("File check fault: stat error: %s", e.Error())
return false
}
if !info.Mode().IsRegular() {
logp.Warn("Harvester: not a regular file: %q %s", info.Mode(), info.Name())
return false
}
return true
}
// Checks if the two files are the same.
func (f *File) IsSameFile(f2 *File) bool {
return os.SameFile(f.FileInfo, f2.FileInfo)
}
// IsSameFile checks if the given File path corresponds with the FileInfo given
func IsSameFile(path string, info os.FileInfo) bool {
fileInfo, err := os.Stat(path)
if err != nil {
logp.Err("Error during file comparison: %s with %s - Error: %s", path, info.Name(), err)
return false
}
return os.SameFile(fileInfo, info)
}
func IsRegularFile(file *os.File) bool {
f := &File{File: file}
return f.IsRegularFile()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.0.0-alpha2

搜索帮助