forked from TrueCloudLab/restic
fs: Use AT_FDCWD in Linux nodeRestoreSymlinkTimestamps
There's no need to open the containing directory. This is exactly what syscall.UtimesNano does, except for the AT_SYMLINK_NOFOLLOW flag.
This commit is contained in:
parent
7c02141548
commit
f967a33ccc
1 changed files with 3 additions and 18 deletions
|
@ -1,33 +1,18 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func nodeRestoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
|
||||
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 {
|
||||
// ignore subsequent errors
|
||||
_ = dir.Close()
|
||||
err := unix.UtimesNanoAt(unix.AT_FDCWD, path, times, unix.AT_SYMLINK_NOFOLLOW)
|
||||
return errors.Wrap(err, "UtimesNanoAt")
|
||||
}
|
||||
|
||||
return dir.Close()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue