restic/internal/fs/node_linux.go

34 lines
665 B
Go
Raw Normal View History

package fs
import (
2024-07-21 13:58:41 +00:00
"os"
"path/filepath"
"syscall"
"golang.org/x/sys/unix"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
)
func nodeRestoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
2024-07-21 13:58:41 +00:00
dir, err := os.Open(fixpath(filepath.Dir(path)))
if err != nil {
return errors.WithStack(err)
}
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()
}