1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file_other.go 898 Bytes
一键复制 编辑 原始数据 按行查看 历史
// +build !windows
package file
import (
"fmt"
"os"
"syscall"
)
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
}
func (fs StateOS) String() string {
return fmt.Sprintf("%d-%d", fs.Inode, fs.Device)
}
// 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
v6.0.0-beta1

搜索帮助