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