This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
forked from elastic/logstash-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filecompare.go
59 lines (49 loc) · 1.46 KB
/
filecompare.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
56
57
58
59
// +build !windows
package main
import (
"os"
"syscall"
)
func is_file_same(path string, info os.FileInfo, state *FileState) bool {
fstat := info.Sys().(*syscall.Stat_t)
return (fstat.Ino == state.Inode && fstat.Dev == state.Device)
}
func is_fileinfo_same(a os.FileInfo, b os.FileInfo) bool {
af := a.Sys().(*syscall.Stat_t)
bf := b.Sys().(*syscall.Stat_t)
return (af.Dev == bf.Dev && af.Ino == bf.Ino)
}
func is_file_renamed(file string, info os.FileInfo, fileinfo map[string]ProspectorInfo, missingfiles map[string]os.FileInfo) string {
// NOTE(driskell): What about using golang's func os.SameFile(fi1, fi2 FileInfo) bool instead?
stat := info.Sys().(*syscall.Stat_t)
for kf, ki := range fileinfo {
if kf == file {
continue
}
ks := ki.fileinfo.Sys().(*syscall.Stat_t)
if stat.Dev == ks.Dev && stat.Ino == ks.Ino {
return kf
}
}
// Now check the missingfiles
for kf, ki := range missingfiles {
ks := ki.Sys().(*syscall.Stat_t)
if stat.Dev == ks.Dev && stat.Ino == ks.Ino {
return kf
}
}
return ""
}
func is_file_renamed_resumelist(file string, info os.FileInfo, initial map[string]*FileState) string {
// NOTE(driskell): What about using golang's func os.SameFile(fi1, fi2 FileInfo) bool instead?
stat := info.Sys().(*syscall.Stat_t)
for kf, ki := range initial {
if kf == file {
continue
}
if stat.Dev == ki.Device && stat.Ino == ki.Inode {
return kf
}
}
return ""
}