mirror of
https://github.com/restic/restic.git
synced 2024-12-24 16:54:00 +00:00
Merge pull request #186 from restic/directory_modtime
Fix ModTime for directories
This commit is contained in:
commit
3517229844
3 changed files with 21 additions and 3 deletions
|
@ -62,7 +62,8 @@ func (e *entry) equals(other *entry) bool {
|
||||||
|
|
||||||
if e.fi.ModTime() != other.fi.ModTime() {
|
if e.fi.ModTime() != other.fi.ModTime() {
|
||||||
fmt.Printf("%s: ModTime does not match\n", e.path)
|
fmt.Printf("%s: ModTime does not match\n", e.path)
|
||||||
// TODO: Fix ModTime for directories, return false
|
// TODO: Fix ModTime for symlinks, return false
|
||||||
|
// see http://grokbase.com/t/gg/golang-nuts/154wnph4y8/go-nuts-no-way-to-utimes-a-symlink
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
node.go
15
node.go
|
@ -155,12 +155,23 @@ func (node Node) restoreMetadata(path string) error {
|
||||||
return errors.Annotate(err, "Chmod")
|
return errors.Annotate(err, "Chmod")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if node.Type != "dir" {
|
||||||
|
err = node.RestoreTimestamps(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (node Node) RestoreTimestamps(path string) error {
|
||||||
var utimes = []syscall.Timespec{
|
var utimes = []syscall.Timespec{
|
||||||
syscall.NsecToTimespec(node.AccessTime.UnixNano()),
|
syscall.NsecToTimespec(node.AccessTime.UnixNano()),
|
||||||
syscall.NsecToTimespec(node.ModTime.UnixNano()),
|
syscall.NsecToTimespec(node.ModTime.UnixNano()),
|
||||||
}
|
}
|
||||||
err = syscall.UtimesNano(path, utimes)
|
|
||||||
if err != nil {
|
if err := syscall.UtimesNano(path, utimes); err != nil {
|
||||||
return errors.Annotate(err, "UtimesNano")
|
return errors.Annotate(err, "UtimesNano")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,12 @@ func (res *Restorer) restoreTo(dst string, dir string, treeID backend.ID) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore directory timestamp at the end. If we would do it earlier, restoring files within
|
||||||
|
// the directory would overwrite the timestamp of the directory they are in.
|
||||||
|
if err := node.RestoreTimestamps(filepath.Join(dst, dir, node.Name)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue