代码拉取完成,页面将自动刷新
// +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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。