forked from TrueCloudLab/restic
c45f8ee075
name old time/op new time/op delta NodeFillUser-8 1.81µs ± 9% 1.50µs ± 5% -17.07% (p=0.000 n=19+20) NodeFromFileInfo-8 1.76µs ± 4% 1.49µs ± 6% -15.63% (p=0.000 n=20+19) name old alloc/op new alloc/op delta NodeFillUser-8 496B ± 0% 352B ± 0% -29.03% (p=0.000 n=20+20) NodeFromFileInfo-8 496B ± 0% 352B ± 0% -29.03% (p=0.000 n=20+20) name old allocs/op new allocs/op delta NodeFillUser-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=20+20) NodeFromFileInfo-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=20+20)
40 lines
900 B
Go
40 lines
900 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")
|
|
}
|
|
defer dir.Close()
|
|
|
|
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 {
|
|
return errors.Wrap(err, "UtimesNanoAt")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
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 }
|