2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 00:20:48 +00:00
restic/internal/restic/node_linux.go
greatroar 0666c4d244 Make restic.{lchown,mknod} regular functions
This way, they can be inlined and dead code can be removed on Windows.
Also fixed some comments.
2021-05-27 22:51:40 +02:00

38 lines
877 B
Go

package restic
import (
"path/filepath"
"syscall"
"golang.org/x/sys/unix"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/fs"
)
func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
dir, err := fs.Open(filepath.Dir(path))
if err != nil {
return errors.Wrap(err, "Open")
}
times := []unix.Timespec{
{Sec: utimes[0].Sec, Nsec: utimes[0].Nsec},
{Sec: utimes[1].Sec, Nsec: utimes[1].Nsec},
}
err = unix.UtimesNanoAt(int(dir.Fd()), filepath.Base(path), times, unix.AT_SYMLINK_NOFOLLOW)
if err != nil {
// ignore subsequent errors
_ = dir.Close()
return errors.Wrap(err, "UtimesNanoAt")
}
return dir.Close()
}
func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim }