forked from elastic/logstash-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 5
/
filestate.go
49 lines (39 loc) · 945 Bytes
/
filestate.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
package main
import (
"os"
)
type FileState struct {
FileStateOS
Source *string `json:"source,omitempty"`
Offset int64 `json:"offset,omitempty"`
TmpOffset int64 `json:"-"`
}
type FileInfo struct {
fileinfo os.FileInfo /* the file info */
}
func NewFileInfo(fileinfo os.FileInfo) *FileInfo {
return &FileInfo{
fileinfo: fileinfo,
}
}
func (fs *FileInfo) SameAs(info os.FileInfo) bool {
return os.SameFile(info, fs.fileinfo)
}
func (fs *FileInfo) Stat() os.FileInfo {
return fs.fileinfo
}
func (fs *FileInfo) Update(fileinfo os.FileInfo, identity *FileIdentity) {
fs.fileinfo = fileinfo
}
func (fs *FileState) Stat() os.FileInfo {
return nil
}
func (fs *FileState) Update(fileinfo os.FileInfo, identity *FileIdentity) {
// Promote to a FileInfo
(*identity) = NewFileInfo(fileinfo)
}
type FileIdentity interface {
SameAs(os.FileInfo) bool
Stat() os.FileInfo
Update(os.FileInfo, *FileIdentity)
}