forked from TrueCloudLab/restic
node/Linux: Implement setting timestamps for symlinks
This commit is contained in:
parent
af06376b5b
commit
44219c5afe
5 changed files with 62 additions and 9 deletions
24
node.go
24
node.go
|
@ -146,13 +146,11 @@ func (node Node) restoreMetadata(path string) error {
|
|||
return errors.Annotate(err, "Lchown")
|
||||
}
|
||||
|
||||
if node.Type == "symlink" {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = os.Chmod(path, node.Mode)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Chmod")
|
||||
if node.Type != "symlink" {
|
||||
err = os.Chmod(path, node.Mode)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Chmod")
|
||||
}
|
||||
}
|
||||
|
||||
if node.Type != "dir" {
|
||||
|
@ -166,12 +164,20 @@ func (node Node) restoreMetadata(path string) error {
|
|||
}
|
||||
|
||||
func (node Node) RestoreTimestamps(path string) error {
|
||||
var utimes = []syscall.Timespec{
|
||||
var utimes = [...]syscall.Timespec{
|
||||
syscall.NsecToTimespec(node.AccessTime.UnixNano()),
|
||||
syscall.NsecToTimespec(node.ModTime.UnixNano()),
|
||||
}
|
||||
|
||||
if err := syscall.UtimesNano(path, utimes); err != nil {
|
||||
if node.Type == "symlink" {
|
||||
if err := node.restoreSymlinkTimestamps(path, utimes); err != nil {
|
||||
return errors.Annotate(err, "UtimesNano")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := syscall.UtimesNano(path, utimes[:]); err != nil {
|
||||
return errors.Annotate(err, "UtimesNano")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue