1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file_other.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
// +build !windows
package input
import (
"os"
"syscall"
"github.com/elastic/beats/libbeat/logp"
)
type FileStateOS struct {
Inode uint64 `json:"inode,omitempty"`
Device uint64 `json:"device,omitempty"`
}
// GetOSFileState returns the FileStateOS for non windows systems
func GetOSFileState(info *os.FileInfo) *FileStateOS {
stat := (*(info)).Sys().(*syscall.Stat_t)
// Convert inode and dev to uint64 to be cross platform compatible
fileState := &FileStateOS{
Inode: uint64(stat.Ino),
Device: uint64(stat.Dev),
}
return fileState
}
// IsSame file checks if the files are identical
func (fs *FileStateOS) IsSame(state *FileStateOS) 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
var perm os.FileMode = 0
return os.OpenFile(path, flag, perm)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.0.0-alpha1

搜索帮助