github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/restic/node_linux.go (about)

     1  package restic
     2  
     3  import (
     4  	"path/filepath"
     5  	"syscall"
     6  
     7  	"golang.org/x/sys/unix"
     8  
     9  	"github.com/restic/restic/internal/errors"
    10  
    11  	"github.com/restic/restic/internal/fs"
    12  )
    13  
    14  func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
    15  	dir, err := fs.Open(filepath.Dir(path))
    16  	defer dir.Close()
    17  	if err != nil {
    18  		return errors.Wrap(err, "Open")
    19  	}
    20  
    21  	times := []unix.Timespec{
    22  		{Sec: utimes[0].Sec, Nsec: utimes[0].Nsec},
    23  		{Sec: utimes[1].Sec, Nsec: utimes[1].Nsec},
    24  	}
    25  
    26  	err = unix.UtimesNanoAt(int(dir.Fd()), filepath.Base(path), times, unix.AT_SYMLINK_NOFOLLOW)
    27  
    28  	if err != nil {
    29  		return errors.Wrap(err, "UtimesNanoAt")
    30  	}
    31  
    32  	return nil
    33  }
    34  
    35  func (s statUnix) atim() syscall.Timespec { return s.Atim }
    36  func (s statUnix) mtim() syscall.Timespec { return s.Mtim }
    37  func (s statUnix) ctim() syscall.Timespec { return s.Ctim }