From a3570af5001e083b58d4d7f11b0b75f3b8d24b1b Mon Sep 17 00:00:00 2001 From: klauspost Date: Mon, 17 Aug 2015 11:10:12 +0200 Subject: [PATCH] Create separate disEntry.equals for Windows. Windows does not have UID/GID the same way as unix, so we don't attempt to compare them. --- cmd/restic/integration_helpers_test.go | 35 +--------------- cmd/restic/integration_helpers_unix_test.go | 41 +++++++++++++++++++ .../integration_helpers_windows_test.go | 27 ++++++++++++ 3 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 cmd/restic/integration_helpers_unix_test.go create mode 100644 cmd/restic/integration_helpers_windows_test.go diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 6fd90ac3f..a31198a53 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "runtime" - "syscall" "testing" . "github.com/restic/restic/test" @@ -70,38 +69,6 @@ func sameModTime(fi1, fi2 os.FileInfo) bool { return fi1.ModTime() == fi2.ModTime() } -func (e *dirEntry) equals(other *dirEntry) bool { - if e.path != other.path { - fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path) - return false - } - - if e.fi.Mode() != other.fi.Mode() { - fmt.Fprintf(os.Stderr, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode()) - return false - } - - if !sameModTime(e.fi, other.fi) { - 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) - stat2, _ := other.fi.Sys().(*syscall.Stat_t) - - if stat.Uid != stat2.Uid { - 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 true -} - // directoriesEqualContents checks if both directories contain exactly the same // contents. func directoriesEqualContents(dir1, dir2 string) bool { @@ -237,6 +204,8 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions)) } OK(t, os.MkdirAll(env.testdata, 0700)) + OK(t, os.MkdirAll(env.cache, 0700)) + OK(t, os.MkdirAll(env.repo, 0700)) f(&env, configureRestic(t, env.cache, env.repo)) diff --git a/cmd/restic/integration_helpers_unix_test.go b/cmd/restic/integration_helpers_unix_test.go new file mode 100644 index 000000000..a182898e8 --- /dev/null +++ b/cmd/restic/integration_helpers_unix_test.go @@ -0,0 +1,41 @@ +//+build !windows + +package main + +import ( + "fmt" + "os" + "syscall" +) + +func (e *dirEntry) equals(other *dirEntry) bool { + if e.path != other.path { + fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path) + return false + } + + if e.fi.Mode() != other.fi.Mode() { + fmt.Fprintf(os.Stderr, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode()) + return false + } + + if !sameModTime(e.fi, other.fi) { + 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) + stat2, _ := other.fi.Sys().(*syscall.Stat_t) + + if stat.Uid != stat2.Uid { + 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 true +} diff --git a/cmd/restic/integration_helpers_windows_test.go b/cmd/restic/integration_helpers_windows_test.go new file mode 100644 index 000000000..d67e9ca11 --- /dev/null +++ b/cmd/restic/integration_helpers_windows_test.go @@ -0,0 +1,27 @@ +//+build windows + +package main + +import ( + "fmt" + "os" +) + +func (e *dirEntry) equals(other *dirEntry) bool { + if e.path != other.path { + fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path) + return false + } + + if e.fi.Mode() != other.fi.Mode() { + fmt.Fprintf(os.Stderr, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode()) + return false + } + + if !sameModTime(e.fi, other.fi) { + fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime()) + return false + } + + return true +}