From 3ac04257a4f88f862b39675b87e8eee7e122b1e9 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 22:27:07 +0200 Subject: [PATCH 1/6] fuse: disable for OpenBSD --- fuse/dir.go | 2 ++ fuse/file.go | 2 ++ fuse/file_test.go | 2 ++ fuse/fuse.go | 2 ++ fuse/link.go | 2 ++ fuse/snapshot.go | 2 ++ 6 files changed, 12 insertions(+) diff --git a/fuse/dir.go b/fuse/dir.go index 7588b31e6..d7d1c6665 100644 --- a/fuse/dir.go +++ b/fuse/dir.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( diff --git a/fuse/file.go b/fuse/file.go index 20e6fdd16..b4148f10c 100644 --- a/fuse/file.go +++ b/fuse/file.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( diff --git a/fuse/file_test.go b/fuse/file_test.go index db48f1e9d..bd966d8b2 100644 --- a/fuse/file_test.go +++ b/fuse/file_test.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( diff --git a/fuse/fuse.go b/fuse/fuse.go index 487d23f10..2ec0cf1fb 100644 --- a/fuse/fuse.go +++ b/fuse/fuse.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( diff --git a/fuse/link.go b/fuse/link.go index 61e05b3fd..074b63b51 100644 --- a/fuse/link.go +++ b/fuse/link.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( diff --git a/fuse/snapshot.go b/fuse/snapshot.go index 99f84e806..ad96f5b1c 100644 --- a/fuse/snapshot.go +++ b/fuse/snapshot.go @@ -1,3 +1,5 @@ +// +build !openbsd + package fuse import ( From 4f8cc1180dde4b1a273aceea0c32dd2b92a33df2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 22:27:16 +0200 Subject: [PATCH 2/6] Vagrantfile: Disable default rsync on /vagrant --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index ae66663bb..b12f1a737 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -85,6 +85,7 @@ end Vagrant.configure(2) do |config| # use rsync to copy content to the folder config.vm.synced_folder ".", "/vagrant/go/src/github.com/restic/restic", :type => "rsync" + config.vm.synced_folder ".", "/vagrant", disabled: true # fix permissions on synced folder config.vm.provision "fix perms", :type => :shell, :inline => fix_perms From c228a212b0692736df29164b054ec43476a36dde Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 23:02:02 +0200 Subject: [PATCH 3/6] SetupTarTestFixture: don't depend on "sh" --- test/helpers.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/helpers.go b/test/helpers.go index 504b582ca..f04ac24ac 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -88,19 +88,18 @@ func RandomReader(seed, size int) *bytes.Reader { // SetupTarTestFixture extracts the tarFile to outputDir. func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) { - err := System("sh", "-c", `(cd "$1" && tar xzf - ) < "$2"`, - "sh", outputDir, tarFile) + f, err := os.Open(tarFile) + defer f.Close() OK(t, err) -} -// System runs the command and returns the exit code. Output is passed on to -// stdout/stderr. -func System(command string, args ...string) error { - cmd := exec.Command(command, args...) + cmd := exec.Command("tar", "xzf", "-") + cmd.Dir = outputDir + + cmd.Stdin = f cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - return cmd.Run() + OK(t, cmd.Run()) } // WithTestEnvironment creates a test environment, extracts the repository From 47219a790f903a1f73c3f169600bcb8407527fdc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 23:09:39 +0200 Subject: [PATCH 4/6] crypto tests: remove dependency on /dev/urandom --- crypto/crypto_test.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index f255181ba..50895c65c 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -2,9 +2,9 @@ package crypto_test import ( "bytes" + "crypto/rand" "io" "io/ioutil" - "os" "testing" "github.com/restic/chunker" @@ -50,10 +50,7 @@ func TestSmallBuffer(t *testing.T) { size := 600 data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext := make([]byte, size/2) @@ -75,10 +72,7 @@ func TestSameBuffer(t *testing.T) { size := 600 data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext := make([]byte, 0, size+crypto.Extension) @@ -124,10 +118,7 @@ func TestLargeEncrypt(t *testing.T) { for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} { data := make([]byte, size) - f, err := os.Open("/dev/urandom") - OK(t, err) - - _, err = io.ReadFull(f, data) + _, err := io.ReadFull(rand.Reader, data) OK(t, err) ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data) From 36ed3add3a2801cbc4609c21ac73830b7e8f501b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 17 Aug 2015 19:40:34 +0200 Subject: [PATCH 5/6] add build constraints for windows --- fuse/dir.go | 1 + fuse/file.go | 1 + fuse/file_test.go | 1 + fuse/fuse.go | 1 + fuse/link.go | 1 + fuse/snapshot.go | 1 + 6 files changed, 6 insertions(+) diff --git a/fuse/dir.go b/fuse/dir.go index d7d1c6665..19f5d569f 100644 --- a/fuse/dir.go +++ b/fuse/dir.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse diff --git a/fuse/file.go b/fuse/file.go index b4148f10c..998ea822c 100644 --- a/fuse/file.go +++ b/fuse/file.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse diff --git a/fuse/file_test.go b/fuse/file_test.go index bd966d8b2..10668ea82 100644 --- a/fuse/file_test.go +++ b/fuse/file_test.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse diff --git a/fuse/fuse.go b/fuse/fuse.go index 2ec0cf1fb..da64f3938 100644 --- a/fuse/fuse.go +++ b/fuse/fuse.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse diff --git a/fuse/link.go b/fuse/link.go index 074b63b51..f963b5832 100644 --- a/fuse/link.go +++ b/fuse/link.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse diff --git a/fuse/snapshot.go b/fuse/snapshot.go index ad96f5b1c..80476cc78 100644 --- a/fuse/snapshot.go +++ b/fuse/snapshot.go @@ -1,4 +1,5 @@ // +build !openbsd +// +build !windows package fuse From 1a47ea4ab80faba3b64b878bc757bd35aff277c3 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 18 Aug 2015 21:05:49 +0200 Subject: [PATCH 6/6] test helpers: add RemoveAll and ResetReadOnly This is mainly needed in Windows, where files and dirs cannot be removed unless they are writeable. --- cmd/restic/integration_fuse_test.go | 4 ++-- cmd/restic/integration_helpers_test.go | 4 ++-- node_test.go | 2 +- test/helpers.go | 31 +++++++++++++++++++++++++- tree_test.go | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cmd/restic/integration_fuse_test.go b/cmd/restic/integration_fuse_test.go index 897e1fc75..f9e75ce66 100644 --- a/cmd/restic/integration_fuse_test.go +++ b/cmd/restic/integration_fuse_test.go @@ -56,7 +56,7 @@ func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan s cmd := &CmdMount{global: &global, ready: ready, done: done} OK(t, cmd.Execute([]string{dir})) if TestCleanup { - OK(t, os.RemoveAll(dir)) + RemoveAll(t, dir) } } @@ -101,7 +101,7 @@ func TestMount(t *testing.T) { OK(t, err) // We remove the mountpoint now to check that cmdMount creates it - OK(t, os.RemoveAll(mountpoint)) + RemoveAll(t, mountpoint) ready := make(chan struct{}, 1) done := make(chan struct{}) diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 6fd90ac3f..07d64af3b 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -216,7 +216,7 @@ func cleanupTempdir(t testing.TB, tempdir string) { return } - OK(t, os.RemoveAll(tempdir)) + RemoveAll(t, tempdir) } // withTestEnvironment creates a test environment and calls f with it. After f has @@ -245,5 +245,5 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions)) return } - OK(t, os.RemoveAll(tempdir)) + RemoveAll(t, tempdir) } diff --git a/node_test.go b/node_test.go index f6104b49b..4eaa014fe 100644 --- a/node_test.go +++ b/node_test.go @@ -109,7 +109,7 @@ func TestNodeRestoreAt(t *testing.T) { defer func() { if TestCleanup { - OK(t, os.RemoveAll(tempdir)) + RemoveAll(t, tempdir) } else { t.Logf("leaving tempdir at %v", tempdir) } diff --git a/test/helpers.go b/test/helpers.go index f04ac24ac..1b09b7a0e 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -59,6 +59,7 @@ func Equals(tb testing.TB, exp, act interface{}) { } } +// ParseID parses s as a backend.ID and panics if that fails. func ParseID(s string) backend.ID { id, err := backend.ParseID(s) if err != nil { @@ -123,7 +124,7 @@ func WithTestEnvironment(t testing.TB, repoFixture string, f func(repodir string return } - OK(t, os.RemoveAll(tempdir)) + RemoveAll(t, tempdir) } // OpenLocalRepo opens the local repository located at dir. @@ -137,3 +138,31 @@ func OpenLocalRepo(t testing.TB, dir string) *repository.Repository { return repo } + +func isFile(fi os.FileInfo) bool { + return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0 +} + +// ResetReadOnly recursively resets the read-only flag recursively for dir. +// This is mainly used for tests on Windows, which is unable to delete a file +// set read-only. +func ResetReadOnly(t testing.TB, dir string) { + OK(t, filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { + if fi.IsDir() { + return os.Chmod(path, 0777) + } + + if isFile(fi) { + return os.Chmod(path, 0666) + } + + return nil + })) +} + +// RemoveAll recursively resets the read-only flag of all files and dirs and +// afterwards uses os.RemoveAll() to remove the path. +func RemoveAll(t testing.TB, path string) { + ResetReadOnly(t, path) + OK(t, os.RemoveAll(path)) +} diff --git a/tree_test.go b/tree_test.go index 2d9cb7b7e..725e80b14 100644 --- a/tree_test.go +++ b/tree_test.go @@ -50,7 +50,7 @@ func TestTree(t *testing.T) { dir := createTempDir(t) defer func() { if TestCleanup { - OK(t, os.RemoveAll(dir)) + RemoveAll(t, dir) } }() }