github.com/hanwen/go-fuse@v1.0.0/internal/utimens/utimens_darwin.go (about)

     1  // Copyright 2018 the Go-FUSE Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package utimens
     6  
     7  import (
     8  	"syscall"
     9  	"time"
    10  
    11  	"github.com/hanwen/go-fuse/fuse"
    12  )
    13  
    14  // timeToTimeval converts time.Time to syscall.Timeval
    15  func timeToTimeval(t *time.Time) syscall.Timeval {
    16  	// Note: This does not use syscall.NsecToTimespec because
    17  	// that does not work properly for times before 1970,
    18  	// see https://github.com/golang/go/issues/12777
    19  	var tv syscall.Timeval
    20  	tv.Usec = int32(t.Nanosecond() / 1000)
    21  	tv.Sec = t.Unix()
    22  	return tv
    23  }
    24  
    25  // Fill converts a and m to a syscall.Timeval slice that can be passed
    26  // to syscall.Utimes. Missing values (if any) are taken from attr
    27  func Fill(a *time.Time, m *time.Time, attr *fuse.Attr) []syscall.Timeval {
    28  	if a == nil {
    29  		a2 := time.Unix(int64(attr.Atime), int64(attr.Atimensec))
    30  		a = &a2
    31  	}
    32  	if m == nil {
    33  		m2 := time.Unix(int64(attr.Mtime), int64(attr.Mtimensec))
    34  		m = &m2
    35  	}
    36  	tv := make([]syscall.Timeval, 2)
    37  	tv[0] = timeToTimeval(a)
    38  	tv[1] = timeToTimeval(m)
    39  	return tv
    40  }