/
exstat_linux.go
56 lines (48 loc) · 1.34 KB
/
exstat_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
56
package file
import (
"os"
"path/filepath"
"syscall"
"time"
)
// linuxExFileInfo stores windows specific file information.
// At the moment all the information we need is available
// through the Sys() interface.
type linuxExFileInfo struct {
os.FileInfo
fid FID
path string
}
// timespecToTime converts a unix timespec into a time.Time. This was
// copied from os/stat_linux.go in the Go source.
func timespecToTime(ts syscall.Timespec) time.Time {
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
}
// CTime returns the creation time (ctime) from stat_t.
func (fi *linuxExFileInfo) CTime() time.Time {
return timespecToTime(fi.Sys().(*syscall.Stat_t).Ctim)
}
// ATime returns the access time (atime) from stat_t
func (fi *linuxExFileInfo) ATime() time.Time {
return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
}
// FID returns the file id based on the inode.
func (fi *linuxExFileInfo) FID() FID {
return fi.fid
}
// Path returns the full path for the file.
func (fi *linuxExFileInfo) Path() string {
return fi.path
}
// newExFileInfo creates a new winExFileInfo from a os.FileInfo.
func newExFileInfo(fi os.FileInfo, path string) *linuxExFileInfo {
fid := FID{
IDLow: fi.Sys().(*syscall.Stat_t).Ino,
}
absolute, _ := filepath.Abs(path)
return &linuxExFileInfo{
FileInfo: fi,
fid: fid,
path: filepath.Clean(absolute),
}
}