mirror of
https://github.com/octoleo/restic.git
synced 2024-11-04 20:37:49 +00:00
commit
6e3486fee8
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -55,25 +56,32 @@ func walkDir(dir string) <-chan *dirEntry {
|
|||||||
|
|
||||||
func (e *dirEntry) equals(other *dirEntry) bool {
|
func (e *dirEntry) equals(other *dirEntry) bool {
|
||||||
if e.path != other.path {
|
if e.path != other.path {
|
||||||
fmt.Fprintf(os.Stderr, "%v: path does not match\n", e.path)
|
fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.fi.Mode() != other.fi.Mode() {
|
if e.fi.Mode() != other.fi.Mode() {
|
||||||
fmt.Fprintf(os.Stderr, "%v: mode does not match\n", e.path)
|
fmt.Fprintf(os.Stderr, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.fi.ModTime() != other.fi.ModTime() {
|
if runtime.GOOS != "darwin" {
|
||||||
fmt.Fprintf(os.Stderr, "%v: ModTime does not match\n", e.path)
|
if e.fi.ModTime() != other.fi.ModTime() {
|
||||||
return false
|
fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime())
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, _ := e.fi.Sys().(*syscall.Stat_t)
|
stat, _ := e.fi.Sys().(*syscall.Stat_t)
|
||||||
stat2, _ := other.fi.Sys().(*syscall.Stat_t)
|
stat2, _ := other.fi.Sys().(*syscall.Stat_t)
|
||||||
|
|
||||||
if stat.Uid != stat2.Uid || stat2.Gid != stat2.Gid {
|
if stat.Uid != stat2.Uid {
|
||||||
fmt.Fprintf(os.Stderr, "%v: UID or GID do not match\n", e.path)
|
fmt.Fprintf(os.Stderr, "%v: UID does not match (%v != %v)\n", e.path, stat.Uid, stat2.Uid)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.Gid != stat2.Gid {
|
||||||
|
fmt.Fprintf(os.Stderr, "%v: GID does not match (%v != %v)\n", e.path, stat.Gid, stat2.Gid)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
node_test.go
35
node_test.go
@ -4,6 +4,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -138,11 +139,33 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||||||
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
||||||
Assert(t, test.GID == n2.GID,
|
Assert(t, test.GID == n2.GID,
|
||||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||||
Assert(t, test.Mode == n2.Mode,
|
|
||||||
"%v: mode doesn't match (%v != %v)", test.Type, test.Mode, n2.Mode)
|
if test.Type != "symlink" {
|
||||||
Assert(t, test.ModTime == n2.ModTime,
|
Assert(t, test.Mode == n2.Mode,
|
||||||
"%v: ModTime dosn't match (%v != %v)", test.Type, test.ModTime, n2.ModTime)
|
"%v: mode doesn't match (%v != %v)", test.Type, test.Mode, n2.Mode)
|
||||||
Assert(t, test.AccessTime == n2.AccessTime,
|
}
|
||||||
"%v: AccessTime doesn't match (%v != %v)", test.Type, test.AccessTime, n2.AccessTime)
|
|
||||||
|
AssertFsTimeEqual(t, "AccessTime", test.Type, test.AccessTime, n2.AccessTime)
|
||||||
|
AssertFsTimeEqual(t, "ModTime", test.Type, test.ModTime, n2.ModTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AssertFsTimeEqual(t *testing.T, label string, nodeType string, t1 time.Time, t2 time.Time) {
|
||||||
|
var equal bool
|
||||||
|
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
// Go currently doesn't support setting timestamps of symbolic links on darwin
|
||||||
|
if nodeType == "symlink" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// HFS+ timestamps don't support sub-second precision,
|
||||||
|
// see https://en.wikipedia.org/wiki/Comparison_of_file_systems
|
||||||
|
diff := int(t1.Sub(t2).Seconds())
|
||||||
|
equal = diff == 0
|
||||||
|
} else {
|
||||||
|
equal = t1.Equal(t2)
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(t, equal, "%s: %s doesn't match (%v != %v)", label, nodeType, t1, t2)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user