2024-08-26 21:03:25 +00:00
|
|
|
package fs
|
2015-02-03 20:18:19 +00:00
|
|
|
|
|
|
|
import (
|
2015-05-14 21:06:11 +00:00
|
|
|
"path/filepath"
|
2015-02-03 20:18:19 +00:00
|
|
|
"syscall"
|
2016-08-30 19:44:10 +00:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2015-05-16 11:25:10 +00:00
|
|
|
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2015-02-03 20:18:19 +00:00
|
|
|
)
|
|
|
|
|
2024-08-26 20:35:22 +00:00
|
|
|
func nodeRestoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
|
2024-08-26 21:03:25 +00:00
|
|
|
dir, err := Open(filepath.Dir(path))
|
2015-05-14 21:06:11 +00:00
|
|
|
if err != nil {
|
2022-10-16 09:32:38 +00:00
|
|
|
return errors.WithStack(err)
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 19:44:10 +00:00
|
|
|
times := []unix.Timespec{
|
|
|
|
{Sec: utimes[0].Sec, Nsec: utimes[0].Nsec},
|
|
|
|
{Sec: utimes[1].Sec, Nsec: utimes[1].Nsec},
|
2015-05-16 11:25:10 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 19:44:10 +00:00
|
|
|
err = unix.UtimesNanoAt(int(dir.Fd()), filepath.Base(path), times, unix.AT_SYMLINK_NOFOLLOW)
|
2015-05-14 21:06:11 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2021-01-30 18:35:46 +00:00
|
|
|
// ignore subsequent errors
|
|
|
|
_ = dir.Close()
|
2016-08-30 19:44:10 +00:00
|
|
|
return errors.Wrap(err, "UtimesNanoAt")
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 18:35:46 +00:00
|
|
|
return dir.Close()
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
2015-08-14 13:57:47 +00:00
|
|
|
|
2020-10-18 21:39:42 +00:00
|
|
|
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 }
|