diff --git a/.golangci.yml b/.golangci.yml index 55ad1a266..44dfcdc7c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,7 +24,7 @@ linters: - govet # make sure names and comments are used according to the conventions - - golint + - revive # detect when assignments to existing variables are not used - ineffassign @@ -51,7 +51,7 @@ issues: # list of things to not warn about exclude: - # golint: do not warn about missing comments for exported stuff - - exported (function|method|var|type|const) `.*` should have comment or be unexported - # golint: ignore constants in all caps + # revive: do not warn about missing comments for exported stuff + - exported (function|method|var|type|const) .* should have comment or be unexported + # revive: ignore constants in all caps - don't use ALL_CAPS in Go names; use CamelCase diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 42433d5b9..a6e83f98f 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -1,3 +1,4 @@ +//go:build debug // +build debug package main diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 9cebb1b05..fbe1cc14e 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package main diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 945d2091f..8978600af 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -37,7 +37,7 @@ import ( "os/exec" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) var version = "0.13.0-dev (compiled manually)" @@ -145,13 +145,13 @@ func checkErrno(err error) error { } func stdinIsTerminal() bool { - return terminal.IsTerminal(int(os.Stdin.Fd())) + return term.IsTerminal(int(os.Stdin.Fd())) } func stdoutIsTerminal() bool { // mintty on windows can use pipes which behave like a posix terminal, // but which are not a terminal handle - return terminal.IsTerminal(int(os.Stdout.Fd())) || stdoutCanUpdateStatus() + return term.IsTerminal(int(os.Stdout.Fd())) || stdoutCanUpdateStatus() } func stdoutCanUpdateStatus() bool { @@ -159,7 +159,7 @@ func stdoutCanUpdateStatus() bool { } func stdoutTerminalWidth() int { - w, _, err := terminal.GetSize(int(os.Stdout.Fd())) + w, _, err := term.GetSize(int(os.Stdout.Fd())) if err != nil { return 0 } @@ -172,12 +172,12 @@ func stdoutTerminalWidth() int { // program execution must revert changes to the terminal configuration itself. // The terminal configuration is only restored while reading a password. func restoreTerminal() { - if !terminal.IsTerminal(int(os.Stdout.Fd())) { + if !term.IsTerminal(int(os.Stdout.Fd())) { return } fd := int(os.Stdout.Fd()) - state, err := terminal.GetState(fd) + state, err := term.GetState(fd) if err != nil { fmt.Fprintf(os.Stderr, "unable to get terminal state: %v\n", err) return @@ -192,7 +192,7 @@ func restoreTerminal() { if !isReadingPassword { return nil } - err := checkErrno(terminal.Restore(fd, state)) + err := checkErrno(term.Restore(fd, state)) if err != nil { fmt.Fprintf(os.Stderr, "unable to restore terminal state: %v\n", err) } @@ -322,7 +322,7 @@ func readPassword(in io.Reader) (password string, err error) { func readPasswordTerminal(in *os.File, out io.Writer, prompt string) (password string, err error) { fmt.Fprint(out, prompt) isReadingPassword = true - buf, err := terminal.ReadPassword(int(in.Fd())) + buf, err := term.ReadPassword(int(in.Fd())) isReadingPassword = false fmt.Fprintln(out) if err != nil { diff --git a/cmd/restic/global_debug.go b/cmd/restic/global_debug.go index 6f04d047b..172f3451b 100644 --- a/cmd/restic/global_debug.go +++ b/cmd/restic/global_debug.go @@ -1,3 +1,4 @@ +//go:build debug || profile // +build debug profile package main diff --git a/cmd/restic/global_release.go b/cmd/restic/global_release.go index f17d99639..7cb2e6caf 100644 --- a/cmd/restic/global_release.go +++ b/cmd/restic/global_release.go @@ -1,3 +1,4 @@ +//go:build !debug && !profile // +build !debug,!profile package main diff --git a/cmd/restic/integration_fuse_test.go b/cmd/restic/integration_fuse_test.go index 7da85881e..1337be88e 100644 --- a/cmd/restic/integration_fuse_test.go +++ b/cmd/restic/integration_fuse_test.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package main diff --git a/cmd/restic/integration_helpers_unix_test.go b/cmd/restic/integration_helpers_unix_test.go index 1130d2638..830d41b3d 100644 --- a/cmd/restic/integration_helpers_unix_test.go +++ b/cmd/restic/integration_helpers_unix_test.go @@ -1,4 +1,5 @@ -//+build !windows +//go:build !windows +// +build !windows package main diff --git a/cmd/restic/integration_helpers_windows_test.go b/cmd/restic/integration_helpers_windows_test.go index f519a1494..a46d1e5cd 100644 --- a/cmd/restic/integration_helpers_windows_test.go +++ b/cmd/restic/integration_helpers_windows_test.go @@ -1,4 +1,5 @@ -//+build windows +//go:build windows +// +build windows package main diff --git a/go.mod b/go.mod index e48168643..c61ca0fd1 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 golang.org/x/text v0.3.6 google.golang.org/api v0.50.0 gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 diff --git a/internal/archiver/archiver_unix_test.go b/internal/archiver/archiver_unix_test.go index f7e827e7e..1167f6852 100644 --- a/internal/archiver/archiver_unix_test.go +++ b/internal/archiver/archiver_unix_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package archiver diff --git a/internal/archiver/archiver_windows_test.go b/internal/archiver/archiver_windows_test.go index 9b3d77898..1254e64ee 100644 --- a/internal/archiver/archiver_windows_test.go +++ b/internal/archiver/archiver_windows_test.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package archiver diff --git a/internal/backend/foreground_sysv.go b/internal/backend/foreground_sysv.go index f60e4242e..0e88a57a1 100644 --- a/internal/backend/foreground_sysv.go +++ b/internal/backend/foreground_sysv.go @@ -1,3 +1,4 @@ +//go:build aix || solaris // +build aix solaris package backend diff --git a/internal/backend/foreground_test.go b/internal/backend/foreground_test.go index 81adefe32..4f701122d 100644 --- a/internal/backend/foreground_test.go +++ b/internal/backend/foreground_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package backend_test diff --git a/internal/backend/foreground_unix.go b/internal/backend/foreground_unix.go index eb0002dad..2b59bdf6c 100644 --- a/internal/backend/foreground_unix.go +++ b/internal/backend/foreground_unix.go @@ -1,3 +1,4 @@ +//go:build !aix && !solaris && !windows // +build !aix,!solaris,!windows package backend diff --git a/internal/backend/local/local_unix.go b/internal/backend/local/local_unix.go index 81250a550..6e1298796 100644 --- a/internal/backend/local/local_unix.go +++ b/internal/backend/local/local_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package local diff --git a/internal/bloblru/cache.go b/internal/bloblru/cache.go index b524f870c..dfd9b2fd1 100644 --- a/internal/bloblru/cache.go +++ b/internal/bloblru/cache.go @@ -22,7 +22,7 @@ type Cache struct { free, size int // Current and max capacity, in bytes. } -// Construct a blob cache that stores at most size bytes worth of blobs. +// New constructs a blob cache that stores at most size bytes worth of blobs. func New(size int) *Cache { c := &Cache{ free: size, diff --git a/internal/debug/debug.go b/internal/debug/debug.go index 9cfeed1e6..8464ba008 100644 --- a/internal/debug/debug.go +++ b/internal/debug/debug.go @@ -1,3 +1,4 @@ +//go:build debug // +build debug package debug diff --git a/internal/debug/debug_release.go b/internal/debug/debug_release.go index 9b4259cea..29e2fb066 100644 --- a/internal/debug/debug_release.go +++ b/internal/debug/debug_release.go @@ -1,3 +1,4 @@ +//go:build !debug // +build !debug package debug diff --git a/internal/debug/hooks.go b/internal/debug/hooks.go index e47084fee..f17b02701 100644 --- a/internal/debug/hooks.go +++ b/internal/debug/hooks.go @@ -1,3 +1,4 @@ +//go:build debug // +build debug package debug diff --git a/internal/debug/hooks_release.go b/internal/debug/hooks_release.go index 86efa9f64..fb7a5bdcd 100644 --- a/internal/debug/hooks_release.go +++ b/internal/debug/hooks_release.go @@ -1,3 +1,4 @@ +//go:build !debug // +build !debug package debug diff --git a/internal/debug/round_tripper_debug.go b/internal/debug/round_tripper_debug.go index 5dfbb64c6..22219f9b7 100644 --- a/internal/debug/round_tripper_debug.go +++ b/internal/debug/round_tripper_debug.go @@ -1,3 +1,4 @@ +//go:build debug // +build debug package debug diff --git a/internal/debug/round_tripper_release.go b/internal/debug/round_tripper_release.go index 6efff2c28..924c5c61e 100644 --- a/internal/debug/round_tripper_release.go +++ b/internal/debug/round_tripper_release.go @@ -1,3 +1,4 @@ +//go:build !debug // +build !debug package debug diff --git a/internal/fs/const_unix.go b/internal/fs/const_unix.go index a90d171b1..fe84cda17 100644 --- a/internal/fs/const_unix.go +++ b/internal/fs/const_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package fs diff --git a/internal/fs/const_windows.go b/internal/fs/const_windows.go index 18c89c27e..f1b263a54 100644 --- a/internal/fs/const_windows.go +++ b/internal/fs/const_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package fs diff --git a/internal/fs/deviceid_unix.go b/internal/fs/deviceid_unix.go index 31efd29ff..c366221ab 100644 --- a/internal/fs/deviceid_unix.go +++ b/internal/fs/deviceid_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package fs diff --git a/internal/fs/deviceid_windows.go b/internal/fs/deviceid_windows.go index 4e2f2f9de..42355817d 100644 --- a/internal/fs/deviceid_windows.go +++ b/internal/fs/deviceid_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package fs diff --git a/internal/fs/file_unix.go b/internal/fs/file_unix.go index f5ea36696..3edc60be6 100644 --- a/internal/fs/file_unix.go +++ b/internal/fs/file_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package fs diff --git a/internal/fs/fs_local_vss.go b/internal/fs/fs_local_vss.go index b3e08fed9..aa3522aea 100644 --- a/internal/fs/fs_local_vss.go +++ b/internal/fs/fs_local_vss.go @@ -117,7 +117,7 @@ func (fs *LocalVss) snapshotPath(path string) string { fs.msgMessage("creating VSS snapshot for [%s]\n", vssVolume) if snapshot, err := NewVssSnapshot(vssVolume, 120, fs.msgError); err != nil { - _ = fs.msgError(vssVolume, errors.Errorf("failed to create snapshot for [%s]: %s\n", + _ = fs.msgError(vssVolume, errors.Errorf("failed to create snapshot for [%s]: %s", vssVolume, err)) fs.failedSnapshots[volumeNameLower] = struct{}{} } else { diff --git a/internal/fs/stat_bsd.go b/internal/fs/stat_bsd.go index d5e8ce550..33a7879f4 100644 --- a/internal/fs/stat_bsd.go +++ b/internal/fs/stat_bsd.go @@ -1,3 +1,4 @@ +//go:build freebsd || darwin || netbsd // +build freebsd darwin netbsd package fs diff --git a/internal/fs/stat_unix.go b/internal/fs/stat_unix.go index 34b98a31e..bf0d5ceca 100644 --- a/internal/fs/stat_unix.go +++ b/internal/fs/stat_unix.go @@ -1,3 +1,4 @@ +//go:build !windows && !darwin && !freebsd && !netbsd // +build !windows,!darwin,!freebsd,!netbsd package fs diff --git a/internal/fs/stat_windows.go b/internal/fs/stat_windows.go index a8f13ccea..ee678d92a 100644 --- a/internal/fs/stat_windows.go +++ b/internal/fs/stat_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package fs diff --git a/internal/fs/vss.go b/internal/fs/vss.go index ca0604906..9995f2d3e 100644 --- a/internal/fs/vss.go +++ b/internal/fs/vss.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package fs diff --git a/internal/fs/vss_windows.go b/internal/fs/vss_windows.go index 8cee09fb1..bd82f4405 100644 --- a/internal/fs/vss_windows.go +++ b/internal/fs/vss_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package fs diff --git a/internal/fuse/dir.go b/internal/fuse/dir.go index c14e28d27..399348312 100644 --- a/internal/fuse/dir.go +++ b/internal/fuse/dir.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package fuse diff --git a/internal/fuse/file.go b/internal/fuse/file.go index 2de2660e3..571d5a865 100644 --- a/internal/fuse/file.go +++ b/internal/fuse/file.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package fuse diff --git a/internal/fuse/meta_dir.go b/internal/fuse/meta_dir.go index b3644fca1..b102965f9 100644 --- a/internal/fuse/meta_dir.go +++ b/internal/fuse/meta_dir.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package fuse diff --git a/internal/fuse/other.go b/internal/fuse/other.go index 575f0257f..f7745172b 100644 --- a/internal/fuse/other.go +++ b/internal/fuse/other.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package fuse diff --git a/internal/fuse/snapshots_dir.go b/internal/fuse/snapshots_dir.go index 4371f6568..40854082e 100644 --- a/internal/fuse/snapshots_dir.go +++ b/internal/fuse/snapshots_dir.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux // +build darwin freebsd linux package fuse diff --git a/internal/limiter/static_limiter_test.go b/internal/limiter/static_limiter_test.go index bd3c62ccb..69712c932 100644 --- a/internal/limiter/static_limiter_test.go +++ b/internal/limiter/static_limiter_test.go @@ -56,7 +56,7 @@ func TestRoundTripperReader(t *testing.T) { _, err := io.ReadFull(rand.Reader, data) test.OK(t, err) - var send *tracedReadCloser = newTracedReadCloser(bytes.NewReader(data)) + send := newTracedReadCloser(bytes.NewReader(data)) var recv *tracedReadCloser rt := limiter.Transport(roundTripper(func(req *http.Request) (*http.Response, error) { diff --git a/internal/restic/lock_unix.go b/internal/restic/lock_unix.go index 266f55580..dbf23fc6c 100644 --- a/internal/restic/lock_unix.go +++ b/internal/restic/lock_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package restic diff --git a/internal/restic/mknod_unix.go b/internal/restic/mknod_unix.go index 7021bf35c..7dd6c60d0 100644 --- a/internal/restic/mknod_unix.go +++ b/internal/restic/mknod_unix.go @@ -1,3 +1,4 @@ +//go:build !freebsd && !windows // +build !freebsd,!windows package restic diff --git a/internal/restic/node.go b/internal/restic/node.go index cd237ac43..54b67c672 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -166,7 +166,7 @@ func (node *Node) CreateAt(ctx context.Context, path string, repo Repository) er case "socket": return nil default: - return errors.Errorf("filetype %q not implemented!\n", node.Type) + return errors.Errorf("filetype %q not implemented", node.Type) } return nil diff --git a/internal/restic/node_aix.go b/internal/restic/node_aix.go index 65914411c..572e33a65 100644 --- a/internal/restic/node_aix.go +++ b/internal/restic/node_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package restic diff --git a/internal/restic/node_freebsd.go b/internal/restic/node_freebsd.go index c06701d24..34d5b272c 100644 --- a/internal/restic/node_freebsd.go +++ b/internal/restic/node_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package restic diff --git a/internal/restic/node_unix.go b/internal/restic/node_unix.go index 05d577a98..976cd7b03 100644 --- a/internal/restic/node_unix.go +++ b/internal/restic/node_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package restic diff --git a/internal/restic/node_unix_test.go b/internal/restic/node_unix_test.go index 204330824..c4fef3710 100644 --- a/internal/restic/node_unix_test.go +++ b/internal/restic/node_unix_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package restic diff --git a/internal/restorer/preallocate_other.go b/internal/restorer/preallocate_other.go index b43afc335..f01757bf4 100644 --- a/internal/restorer/preallocate_other.go +++ b/internal/restorer/preallocate_other.go @@ -1,3 +1,4 @@ +//go:build !linux && !darwin // +build !linux,!darwin package restorer diff --git a/internal/restorer/restorer_unix_test.go b/internal/restorer/restorer_unix_test.go index f3f23cd16..13e318c98 100644 --- a/internal/restorer/restorer_unix_test.go +++ b/internal/restorer/restorer_unix_test.go @@ -1,4 +1,5 @@ -//+build !windows +//go:build !windows +// +build !windows package restorer diff --git a/internal/ui/progress/counter_test.go b/internal/ui/progress/counter_test.go index 49a99f7ee..85695d209 100644 --- a/internal/ui/progress/counter_test.go +++ b/internal/ui/progress/counter_test.go @@ -61,7 +61,7 @@ func TestCounter(t *testing.T) { func TestCounterNil(t *testing.T) { // Shouldn't panic. - var c *progress.Counter = nil + var c *progress.Counter c.Add(1) c.Done() } diff --git a/internal/ui/signals/signals_bsd.go b/internal/ui/signals/signals_bsd.go index be3ab8882..d96e48c4e 100644 --- a/internal/ui/signals/signals_bsd.go +++ b/internal/ui/signals/signals_bsd.go @@ -1,3 +1,4 @@ +//go:build darwin || dragonfly || freebsd || netbsd || openbsd // +build darwin dragonfly freebsd netbsd openbsd package signals diff --git a/internal/ui/signals/signals_sysv.go b/internal/ui/signals/signals_sysv.go index a3b4eb29e..9480c1c99 100644 --- a/internal/ui/signals/signals_sysv.go +++ b/internal/ui/signals/signals_sysv.go @@ -1,3 +1,4 @@ +//go:build aix || linux || solaris // +build aix linux solaris package signals diff --git a/internal/ui/termstatus/background.go b/internal/ui/termstatus/background.go index 8c1e9f162..4834a460f 100644 --- a/internal/ui/termstatus/background.go +++ b/internal/ui/termstatus/background.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package termstatus diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index ce6593f37..88c4f898e 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -10,7 +10,7 @@ import ( "strings" "unicode" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" "golang.org/x/text/width" ) @@ -321,7 +321,7 @@ func (t *Terminal) SetStatus(lines []string) { var width int if t.canUpdateStatus { var err error - width, _, err = terminal.GetSize(int(t.fd)) + width, _, err = term.GetSize(int(t.fd)) if err != nil || width <= 0 { // use 80 columns by default width = 80 diff --git a/internal/ui/termstatus/terminal_unix.go b/internal/ui/termstatus/terminal_unix.go index 67ce06b0b..719016939 100644 --- a/internal/ui/termstatus/terminal_unix.go +++ b/internal/ui/termstatus/terminal_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package termstatus @@ -6,7 +7,7 @@ import ( "io" "os" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) // clearCurrentLine removes all characters from the current line and resets the @@ -23,7 +24,7 @@ func moveCursorUp(wr io.Writer, fd uintptr) func(io.Writer, uintptr, int) { // CanUpdateStatus returns true if status lines can be printed, the process // output is not redirected to a file or pipe. func CanUpdateStatus(fd uintptr) bool { - if !terminal.IsTerminal(int(fd)) { + if !term.IsTerminal(int(fd)) { return false } term := os.Getenv("TERM") diff --git a/internal/ui/termstatus/terminal_windows.go b/internal/ui/termstatus/terminal_windows.go index f7217e35d..d1358c022 100644 --- a/internal/ui/termstatus/terminal_windows.go +++ b/internal/ui/termstatus/terminal_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package termstatus