Use ModTime on systems that don't provide Atim file stat field

This commit is contained in:
Andrey Beletsky 2020-04-03 19:47:45 +07:00 committed by Niko Storni
parent 4a9f127ecc
commit 1bf3cb81b3
3 changed files with 29 additions and 8 deletions

17
store/atime_linux.go Normal file
View file

@ -0,0 +1,17 @@
// +build linux
package store
import (
"os"
"syscall"
"time"
)
func timespecToTime(ts syscall.Timespec) time.Time {
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
}
func atime(fi os.FileInfo) time.Time {
return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
}

12
store/atime_universal.go Normal file
View file

@ -0,0 +1,12 @@
// +build !linux
package store
import (
"os"
"time"
)
func atime(fi os.FileInfo) time.Time {
return fi.ModTime()
}

View file

@ -227,11 +227,3 @@ func (d *DiskBlobStore) WipeOldestBlobs() (err error) {
} }
return nil return nil
} }
func timespecToTime(ts syscall.Timespec) time.Time {
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
}
func atime(fi os.FileInfo) time.Time {
return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
}