restic/internal/restic/node_linux.go

42 lines
937 B
Go
Raw Normal View History

package restic
import (
"path/filepath"
"syscall"
"golang.org/x/sys/unix"
2017-07-23 12:21:03 +00:00
"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 {
2016-08-29 19:38:34 +00:00
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 {
2021-01-30 18:35:46 +00:00
// ignore subsequent errors
_ = dir.Close()
return errors.Wrap(err, "UtimesNanoAt")
}
2021-01-30 18:35:46 +00:00
return dir.Close()
}
2019-03-06 14:41:49 +00:00
func (node Node) device() int {
return int(node.Device)
}
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 }