2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 22:27:35 +00:00

Merge pull request #2990 from MichaelEischer/fix-goreport-warnings

Fix some goreport warnings
This commit is contained in:
Alexander Neumann 2020-10-12 20:44:56 +02:00 committed by GitHub
commit 56883817d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 103 additions and 105 deletions

View File

@ -44,7 +44,6 @@ func createFileSetPerHardlink(dir string) map[uint64][]string {
}
for i, f := range files {
linkTests[uint64(i)] = append(linkTests[uint64(i)], f.Name())
i++
}
return linkTests
}

View File

@ -513,7 +513,7 @@ func TestBackupErrors(t *testing.T) {
gopts := env.gopts
gopts.stderr = ioutil.Discard
err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts)
rtest.Assert(t, err != nil, "Assumed failure, but no error occured.")
rtest.Assert(t, err != nil, "Assumed failure, but no error occurred.")
rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned")
snapshotIDs := testRunList(t, "snapshots", env.gopts)
rtest.Assert(t, len(snapshotIDs) == 1,
@ -1665,7 +1665,7 @@ func TestDiff(t *testing.T) {
rtest.OK(t, os.Mkdir(modfile+"4", 0755))
testRunBackup(t, "", []string{datadir}, opts, env.gopts)
snapshots, secondSnapshotID := lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts))
_, secondSnapshotID := lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts))
_, err := testRunDiffOutput(env.gopts, "", secondSnapshotID)
rtest.Assert(t, err != nil, "expected error on invalid snapshot id")

View File

@ -2094,7 +2094,7 @@ func TestMetadataChanged(t *testing.T) {
want.Group = ""
// make another snapshot
snapshotID, node3 := snapshot(t, repo, fs, snapshotID, "testfile")
_, node3 := snapshot(t, repo, fs, snapshotID, "testfile")
// Override username and group to empty string - in case underlying system has user with UID 51234
// See https://github.com/restic/restic/issues/2372
node3.User = ""

View File

@ -33,15 +33,15 @@ func TestScanner(t *testing.T) {
},
},
want: map[string]ScanStats{
filepath.FromSlash("other"): ScanStats{Files: 1, Bytes: 12},
filepath.FromSlash("work/foo"): ScanStats{Files: 2, Bytes: 15},
filepath.FromSlash("work/foo.txt"): ScanStats{Files: 3, Bytes: 28},
filepath.FromSlash("work/subdir/bar.txt"): ScanStats{Files: 4, Bytes: 45},
filepath.FromSlash("work/subdir/other"): ScanStats{Files: 5, Bytes: 60},
filepath.FromSlash("work/subdir"): ScanStats{Files: 5, Dirs: 1, Bytes: 60},
filepath.FromSlash("work"): ScanStats{Files: 5, Dirs: 2, Bytes: 60},
filepath.FromSlash("."): ScanStats{Files: 5, Dirs: 3, Bytes: 60},
filepath.FromSlash(""): ScanStats{Files: 5, Dirs: 3, Bytes: 60},
filepath.FromSlash("other"): {Files: 1, Bytes: 12},
filepath.FromSlash("work/foo"): {Files: 2, Bytes: 15},
filepath.FromSlash("work/foo.txt"): {Files: 3, Bytes: 28},
filepath.FromSlash("work/subdir/bar.txt"): {Files: 4, Bytes: 45},
filepath.FromSlash("work/subdir/other"): {Files: 5, Bytes: 60},
filepath.FromSlash("work/subdir"): {Files: 5, Dirs: 1, Bytes: 60},
filepath.FromSlash("work"): {Files: 5, Dirs: 2, Bytes: 60},
filepath.FromSlash("."): {Files: 5, Dirs: 3, Bytes: 60},
filepath.FromSlash(""): {Files: 5, Dirs: 3, Bytes: 60},
},
},
{
@ -68,12 +68,12 @@ func TestScanner(t *testing.T) {
return false
},
want: map[string]ScanStats{
filepath.FromSlash("work/foo.txt"): ScanStats{Files: 1, Bytes: 13},
filepath.FromSlash("work/subdir/bar.txt"): ScanStats{Files: 2, Bytes: 30},
filepath.FromSlash("work/subdir"): ScanStats{Files: 2, Dirs: 1, Bytes: 30},
filepath.FromSlash("work"): ScanStats{Files: 2, Dirs: 2, Bytes: 30},
filepath.FromSlash("."): ScanStats{Files: 2, Dirs: 3, Bytes: 30},
filepath.FromSlash(""): ScanStats{Files: 2, Dirs: 3, Bytes: 30},
filepath.FromSlash("work/foo.txt"): {Files: 1, Bytes: 13},
filepath.FromSlash("work/subdir/bar.txt"): {Files: 2, Bytes: 30},
filepath.FromSlash("work/subdir"): {Files: 2, Dirs: 1, Bytes: 30},
filepath.FromSlash("work"): {Files: 2, Dirs: 2, Bytes: 30},
filepath.FromSlash("."): {Files: 2, Dirs: 3, Bytes: 30},
filepath.FromSlash(""): {Files: 2, Dirs: 3, Bytes: 30},
},
},
}

View File

@ -150,34 +150,34 @@ func TestTree(t *testing.T) {
{
targets: []string{"foo"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Path: "foo", Root: "."},
"foo": {Path: "foo", Root: "."},
}},
},
{
targets: []string{"foo", "bar", "baz"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Path: "foo", Root: "."},
"bar": Tree{Path: "bar", Root: "."},
"baz": Tree{Path: "baz", Root: "."},
"foo": {Path: "foo", Root: "."},
"bar": {Path: "bar", Root: "."},
"baz": {Path: "baz", Root: "."},
}},
},
{
targets: []string{"foo/user1", "foo/user2", "foo/other"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/user2")},
"other": Tree{Path: filepath.FromSlash("foo/other")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("foo/user1")},
"user2": {Path: filepath.FromSlash("foo/user2")},
"other": {Path: filepath.FromSlash("foo/other")},
}},
}},
},
{
targets: []string{"foo/work/user1", "foo/work/user2"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": Tree{FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/work/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/work/user2")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": {FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("foo/work/user1")},
"user2": {Path: filepath.FromSlash("foo/work/user2")},
}},
}},
}},
@ -185,50 +185,50 @@ func TestTree(t *testing.T) {
{
targets: []string{"foo/user1", "bar/user1", "foo/other"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/user1")},
"other": Tree{Path: filepath.FromSlash("foo/other")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("foo/user1")},
"other": {Path: filepath.FromSlash("foo/other")},
}},
"bar": Tree{Root: ".", FileInfoPath: "bar", Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("bar/user1")},
"bar": {Root: ".", FileInfoPath: "bar", Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("bar/user1")},
}},
}},
},
{
targets: []string{"../work"},
want: Tree{Nodes: map[string]Tree{
"work": Tree{Root: "..", Path: filepath.FromSlash("../work")},
"work": {Root: "..", Path: filepath.FromSlash("../work")},
}},
},
{
targets: []string{"../work/other"},
want: Tree{Nodes: map[string]Tree{
"work": Tree{Root: "..", FileInfoPath: filepath.FromSlash("../work"), Nodes: map[string]Tree{
"other": Tree{Path: filepath.FromSlash("../work/other")},
"work": {Root: "..", FileInfoPath: filepath.FromSlash("../work"), Nodes: map[string]Tree{
"other": {Path: filepath.FromSlash("../work/other")},
}},
}},
},
{
targets: []string{"foo/user1", "../work/other", "foo/user2"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/user2")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("foo/user1")},
"user2": {Path: filepath.FromSlash("foo/user2")},
}},
"work": Tree{Root: "..", FileInfoPath: filepath.FromSlash("../work"), Nodes: map[string]Tree{
"other": Tree{Path: filepath.FromSlash("../work/other")},
"work": {Root: "..", FileInfoPath: filepath.FromSlash("../work"), Nodes: map[string]Tree{
"other": {Path: filepath.FromSlash("../work/other")},
}},
}},
},
{
targets: []string{"foo/user1", "../foo/other", "foo/user2"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/user2")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"user1": {Path: filepath.FromSlash("foo/user1")},
"user2": {Path: filepath.FromSlash("foo/user2")},
}},
"foo-1": Tree{Root: "..", FileInfoPath: filepath.FromSlash("../foo"), Nodes: map[string]Tree{
"other": Tree{Path: filepath.FromSlash("../foo/other")},
"foo-1": {Root: "..", FileInfoPath: filepath.FromSlash("../foo"), Nodes: map[string]Tree{
"other": {Path: filepath.FromSlash("../foo/other")},
}},
}},
},
@ -241,12 +241,12 @@ func TestTree(t *testing.T) {
},
targets: []string{"foo", "foo/work"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{
"foo": {
Root: ".",
FileInfoPath: "foo",
Nodes: map[string]Tree{
"file": Tree{Path: filepath.FromSlash("foo/file")},
"work": Tree{Path: filepath.FromSlash("foo/work")},
"file": {Path: filepath.FromSlash("foo/file")},
"work": {Path: filepath.FromSlash("foo/work")},
},
},
}},
@ -262,12 +262,12 @@ func TestTree(t *testing.T) {
},
targets: []string{"foo/work", "foo"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{
"foo": {
Root: ".",
FileInfoPath: "foo",
Nodes: map[string]Tree{
"file": Tree{Path: filepath.FromSlash("foo/file")},
"work": Tree{Path: filepath.FromSlash("foo/work")},
"file": {Path: filepath.FromSlash("foo/file")},
"work": {Path: filepath.FromSlash("foo/work")},
},
},
}},
@ -283,12 +283,12 @@ func TestTree(t *testing.T) {
},
targets: []string{"foo/work", "foo/work/user2"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": Tree{
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": {
FileInfoPath: filepath.FromSlash("foo/work"),
Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/work/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/work/user2")},
"user1": {Path: filepath.FromSlash("foo/work/user1")},
"user2": {Path: filepath.FromSlash("foo/work/user2")},
},
},
}},
@ -305,11 +305,11 @@ func TestTree(t *testing.T) {
},
targets: []string{"foo/work/user2", "foo/work"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": Tree{FileInfoPath: filepath.FromSlash("foo/work"),
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": {FileInfoPath: filepath.FromSlash("foo/work"),
Nodes: map[string]Tree{
"user1": Tree{Path: filepath.FromSlash("foo/work/user1")},
"user2": Tree{Path: filepath.FromSlash("foo/work/user2")},
"user1": {Path: filepath.FromSlash("foo/work/user1")},
"user2": {Path: filepath.FromSlash("foo/work/user2")},
},
},
}},
@ -333,17 +333,17 @@ func TestTree(t *testing.T) {
},
targets: []string{"foo/work/user2/data/secret", "foo"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"other": Tree{Path: filepath.FromSlash("foo/other")},
"work": Tree{FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user2": Tree{FileInfoPath: filepath.FromSlash("foo/work/user2"), Nodes: map[string]Tree{
"data": Tree{FileInfoPath: filepath.FromSlash("foo/work/user2/data"), Nodes: map[string]Tree{
"secret": Tree{
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"other": {Path: filepath.FromSlash("foo/other")},
"work": {FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user2": {FileInfoPath: filepath.FromSlash("foo/work/user2"), Nodes: map[string]Tree{
"data": {FileInfoPath: filepath.FromSlash("foo/work/user2/data"), Nodes: map[string]Tree{
"secret": {
Path: filepath.FromSlash("foo/work/user2/data/secret"),
},
}},
}},
"user3": Tree{Path: filepath.FromSlash("foo/work/user3")},
"user3": {Path: filepath.FromSlash("foo/work/user3")},
}},
}},
}},
@ -369,15 +369,15 @@ func TestTree(t *testing.T) {
unix: true,
targets: []string{"mnt/driveA", "mnt/driveA/work/driveB"},
want: Tree{Nodes: map[string]Tree{
"mnt": Tree{Root: ".", FileInfoPath: filepath.FromSlash("mnt"), Nodes: map[string]Tree{
"driveA": Tree{FileInfoPath: filepath.FromSlash("mnt/driveA"), Nodes: map[string]Tree{
"work": Tree{FileInfoPath: filepath.FromSlash("mnt/driveA/work"), Nodes: map[string]Tree{
"driveB": Tree{
"mnt": {Root: ".", FileInfoPath: filepath.FromSlash("mnt"), Nodes: map[string]Tree{
"driveA": {FileInfoPath: filepath.FromSlash("mnt/driveA"), Nodes: map[string]Tree{
"work": {FileInfoPath: filepath.FromSlash("mnt/driveA/work"), Nodes: map[string]Tree{
"driveB": {
Path: filepath.FromSlash("mnt/driveA/work/driveB"),
},
"test1": Tree{Path: filepath.FromSlash("mnt/driveA/work/test1")},
"test1": {Path: filepath.FromSlash("mnt/driveA/work/test1")},
}},
"test2": Tree{Path: filepath.FromSlash("mnt/driveA/test2")},
"test2": {Path: filepath.FromSlash("mnt/driveA/test2")},
}},
}},
}},
@ -385,9 +385,9 @@ func TestTree(t *testing.T) {
{
targets: []string{"foo/work/user", "foo/work/user"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": Tree{FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user": Tree{Path: filepath.FromSlash("foo/work/user")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": {FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user": {Path: filepath.FromSlash("foo/work/user")},
}},
}},
}},
@ -395,9 +395,9 @@ func TestTree(t *testing.T) {
{
targets: []string{"./foo/work/user", "foo/work/user"},
want: Tree{Nodes: map[string]Tree{
"foo": Tree{Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": Tree{FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user": Tree{Path: filepath.FromSlash("foo/work/user")},
"foo": {Root: ".", FileInfoPath: "foo", Nodes: map[string]Tree{
"work": {FileInfoPath: filepath.FromSlash("foo/work"), Nodes: map[string]Tree{
"user": {Path: filepath.FromSlash("foo/work/user")},
}},
}},
}},
@ -406,10 +406,10 @@ func TestTree(t *testing.T) {
win: true,
targets: []string{`c:\users\foobar\temp`},
want: Tree{Nodes: map[string]Tree{
"c": Tree{Root: `c:\`, FileInfoPath: `c:\`, Nodes: map[string]Tree{
"users": Tree{FileInfoPath: `c:\users`, Nodes: map[string]Tree{
"foobar": Tree{FileInfoPath: `c:\users\foobar`, Nodes: map[string]Tree{
"temp": Tree{Path: `c:\users\foobar\temp`},
"c": {Root: `c:\`, FileInfoPath: `c:\`, Nodes: map[string]Tree{
"users": {FileInfoPath: `c:\users`, Nodes: map[string]Tree{
"foobar": {FileInfoPath: `c:\users\foobar`, Nodes: map[string]Tree{
"temp": {Path: `c:\users\foobar\temp`},
}},
}},
}},

View File

@ -3,13 +3,13 @@
package fuse
import (
"context"
"os"
"path/filepath"
"sync"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/restic"

View File

@ -3,6 +3,7 @@
package fuse
import (
"context"
"sort"
"github.com/restic/restic/internal/debug"
@ -11,7 +12,6 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
// The default block size to report in stat

View File

@ -4,13 +4,12 @@ package fuse
import (
"bytes"
"context"
"math/rand"
"os"
"testing"
"time"
"golang.org/x/net/context"
"github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic"

View File

@ -3,10 +3,11 @@
package fuse
import (
"context"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
)
// Statically ensure that *link implements the given interface

View File

@ -3,12 +3,11 @@
package fuse
import (
"context"
"os"
"github.com/restic/restic/internal/debug"
"golang.org/x/net/context"
"bazil.org/fuse"
"bazil.org/fuse/fs"
)

View File

@ -3,9 +3,10 @@
package fuse
import (
"context"
"bazil.org/fuse"
"github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
)
type other struct {

View File

@ -3,6 +3,7 @@
package fuse
import (
"context"
"fmt"
"os"
"time"
@ -10,8 +11,6 @@ import (
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
"bazil.org/fuse"
"bazil.org/fuse/fs"
)

View File

@ -715,7 +715,7 @@ func (r *Repository) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte
// first try to add to pending blobs; if not successful, this blob is already known
known = !r.idx.addPending(newID, t)
// only save when needed or explicitely told
// only save when needed or explicitly told
if !known || storeDuplicate {
err = r.SaveAndEncrypt(ctx, t, buf, newID)
}

View File

@ -18,7 +18,7 @@
//
// Implementation does not guarantee order in which blobs are written to the
// target files and, for example, the last blob of a file can be written to the
// file before any of the preceeding file blobs. It is therefore possible to
// file before any of the preceding file blobs. It is therefore possible to
// have gaps in the data written to the target files if restore fails or
// interrupted by the user.
package restorer

View File

@ -244,7 +244,7 @@ func TestWalker(t *testing.T) {
}),
checkSkipFor(
map[string]struct{}{
"/subdir": struct{}{},
"/subdir": {},
}, []string{
"/",
"/foo",
@ -299,7 +299,7 @@ func TestWalker(t *testing.T) {
}),
checkSkipFor(
map[string]struct{}{
"/subdir1": struct{}{},
"/subdir1": {},
}, []string{
"/",
"/foo",
@ -312,8 +312,8 @@ func TestWalker(t *testing.T) {
),
checkSkipFor(
map[string]struct{}{
"/subdir1": struct{}{},
"/subdir2/subsubdir2": struct{}{},
"/subdir1": {},
"/subdir2/subsubdir2": {},
}, []string{
"/",
"/foo",
@ -325,7 +325,7 @@ func TestWalker(t *testing.T) {
),
checkSkipFor(
map[string]struct{}{
"/foo": struct{}{},
"/foo": {},
}, []string{
"/",
"/foo",
@ -390,7 +390,7 @@ func TestWalker(t *testing.T) {
}),
checkIgnore(
map[string]struct{}{
"/subdir1": struct{}{},
"/subdir1": {},
}, map[string]bool{
"/subdir1": true,
}, []string{
@ -415,7 +415,7 @@ func TestWalker(t *testing.T) {
),
checkIgnore(
map[string]struct{}{
"/subdir2": struct{}{},
"/subdir2": {},
}, map[string]bool{
"/subdir2": true,
}, []string{