-
Notifications
You must be signed in to change notification settings - Fork 3
/
transport_linux.go
55 lines (47 loc) · 1.26 KB
/
transport_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build amd64,linux
package bitflow
import (
"os"
"syscall"
log "github.com/sirupsen/logrus"
)
type fileVanishChecker struct {
currentIno uint64
}
func (f *fileVanishChecker) setCurrentFile(name string) error {
stat, err := os.Stat(name)
if err == nil {
f.currentIno = stat.Sys().(*syscall.Stat_t).Ino
}
return err
}
func (f *fileVanishChecker) hasFileVanished(name string) bool {
info, err := os.Stat(name)
if err != nil {
log.WithField("file", name).Warn("Error stating opened output file:", err)
return true
} else {
newIno := info.Sys().(*syscall.Stat_t).Ino
if newIno != f.currentIno {
log.WithField("file", name).Warnf("Output file inumber has changed, file was moved or vanished (%v -> %v)", f.currentIno, newIno)
return true
}
}
return false
}
// IsFileClosedError returns true, if the given error likely originates from intentionally
// closing a file, while it is still being read concurrently.
func IsFileClosedError(err error) bool {
pathErr, ok := err.(*os.PathError)
return ok && pathErr.Err == syscall.EBADF
}
func IsBrokenPipeError(err error) bool {
if err == syscall.EPIPE {
return true
} else {
if syscallErr, ok := err.(*os.SyscallError); ok && IsBrokenPipeError(syscallErr.Err) {
return true
}
}
return false
}