1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
file_other.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
urso 提交于 2016-10-28 15:52 . Address some filebeat golint reports
// +build !windows
package file
import (
"os"
"syscall"
"github.com/elastic/beats/libbeat/logp"
)
type StateOS struct {
Inode uint64 `json:"inode,"`
Device uint64 `json:"device,"`
}
// GetOSState returns the FileStateOS for non windows systems
func GetOSState(info os.FileInfo) StateOS {
stat := info.Sys().(*syscall.Stat_t)
// Convert inode and dev to uint64 to be cross platform compatible
fileState := StateOS{
Inode: uint64(stat.Ino),
Device: uint64(stat.Dev),
}
return fileState
}
// IsSame file checks if the files are identical
func (fs StateOS) IsSame(state StateOS) bool {
return fs.Inode == state.Inode && fs.Device == state.Device
}
// SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile
func SafeFileRotate(path, tempfile string) error {
if e := os.Rename(tempfile, path); e != nil {
logp.Err("Rotate error: %s", e)
return e
}
return nil
}
// ReadOpen opens a file for reading only
func ReadOpen(path string) (*os.File, error) {
flag := os.O_RDONLY
perm := os.FileMode(0)
return os.OpenFile(path, flag, perm)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.6.5

搜索帮助