small refactor*
This commit is contained in:
parent
b6b541e050
commit
24a4d30275
232 changed files with 2164 additions and 1906 deletions
server/pkg/go-nfs
32
server/pkg/go-nfs/time.go
Normal file
32
server/pkg/go-nfs/time.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package nfs
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// FileTime is the NFS wire time format
|
||||
// This is equivalent to go-nfs-client/nfs.NFS3Time
|
||||
type FileTime struct {
|
||||
Seconds uint32
|
||||
Nseconds uint32
|
||||
}
|
||||
|
||||
// ToNFSTime generates the nfs 64bit time format from a golang time.
|
||||
func ToNFSTime(t time.Time) FileTime {
|
||||
return FileTime{
|
||||
Seconds: uint32(t.Unix()),
|
||||
Nseconds: uint32(t.UnixNano() % int64(time.Second)),
|
||||
}
|
||||
}
|
||||
|
||||
// Native generates a golang time from an nfs time spec
|
||||
func (t FileTime) Native() *time.Time {
|
||||
ts := time.Unix(int64(t.Seconds), int64(t.Nseconds))
|
||||
return &ts
|
||||
}
|
||||
|
||||
// EqualTimespec returns if this time is equal to a local time spec
|
||||
func (t FileTime) EqualTimespec(sec int64, nsec int64) bool {
|
||||
// TODO: bounds check on sec/nsec overflow
|
||||
return t.Nseconds == uint32(nsec) && t.Seconds == uint32(sec)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue