2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-07 11:30:49 +00:00

Merge pull request #3683 from MichaelEischer/fix-golangci-lint-warnings

Fix golangci lint warnings
This commit is contained in:
Alexander Neumann 2022-03-29 11:45:10 +02:00 committed by GitHub
commit db8a958991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 72 additions and 24 deletions

View File

@ -24,7 +24,7 @@ linters:
- govet - govet
# make sure names and comments are used according to the conventions # make sure names and comments are used according to the conventions
- golint - revive
# detect when assignments to existing variables are not used # detect when assignments to existing variables are not used
- ineffassign - ineffassign
@ -51,7 +51,7 @@ issues:
# list of things to not warn about # list of things to not warn about
exclude: exclude:
# golint: do not warn about missing comments for exported stuff # revive: do not warn about missing comments for exported stuff
- exported (function|method|var|type|const) `.*` should have comment or be unexported - exported (function|method|var|type|const) .* should have comment or be unexported
# golint: ignore constants in all caps # revive: ignore constants in all caps
- don't use ALL_CAPS in Go names; use CamelCase - don't use ALL_CAPS in Go names; use CamelCase

View File

@ -1,3 +1,4 @@
//go:build debug
// +build debug // +build debug
package main package main

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package main package main

View File

@ -37,7 +37,7 @@ import (
"os/exec" "os/exec"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
) )
var version = "0.13.0-dev (compiled manually)" var version = "0.13.0-dev (compiled manually)"
@ -145,13 +145,13 @@ func checkErrno(err error) error {
} }
func stdinIsTerminal() bool { func stdinIsTerminal() bool {
return terminal.IsTerminal(int(os.Stdin.Fd())) return term.IsTerminal(int(os.Stdin.Fd()))
} }
func stdoutIsTerminal() bool { func stdoutIsTerminal() bool {
// mintty on windows can use pipes which behave like a posix terminal, // mintty on windows can use pipes which behave like a posix terminal,
// but which are not a terminal handle // 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 { func stdoutCanUpdateStatus() bool {
@ -159,7 +159,7 @@ func stdoutCanUpdateStatus() bool {
} }
func stdoutTerminalWidth() int { func stdoutTerminalWidth() int {
w, _, err := terminal.GetSize(int(os.Stdout.Fd())) w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil { if err != nil {
return 0 return 0
} }
@ -172,12 +172,12 @@ func stdoutTerminalWidth() int {
// program execution must revert changes to the terminal configuration itself. // program execution must revert changes to the terminal configuration itself.
// The terminal configuration is only restored while reading a password. // The terminal configuration is only restored while reading a password.
func restoreTerminal() { func restoreTerminal() {
if !terminal.IsTerminal(int(os.Stdout.Fd())) { if !term.IsTerminal(int(os.Stdout.Fd())) {
return return
} }
fd := int(os.Stdout.Fd()) fd := int(os.Stdout.Fd())
state, err := terminal.GetState(fd) state, err := term.GetState(fd)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "unable to get terminal state: %v\n", err) fmt.Fprintf(os.Stderr, "unable to get terminal state: %v\n", err)
return return
@ -192,7 +192,7 @@ func restoreTerminal() {
if !isReadingPassword { if !isReadingPassword {
return nil return nil
} }
err := checkErrno(terminal.Restore(fd, state)) err := checkErrno(term.Restore(fd, state))
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "unable to restore terminal state: %v\n", err) 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) { func readPasswordTerminal(in *os.File, out io.Writer, prompt string) (password string, err error) {
fmt.Fprint(out, prompt) fmt.Fprint(out, prompt)
isReadingPassword = true isReadingPassword = true
buf, err := terminal.ReadPassword(int(in.Fd())) buf, err := term.ReadPassword(int(in.Fd()))
isReadingPassword = false isReadingPassword = false
fmt.Fprintln(out) fmt.Fprintln(out)
if err != nil { if err != nil {

View File

@ -1,3 +1,4 @@
//go:build debug || profile
// +build debug profile // +build debug profile
package main package main

View File

@ -1,3 +1,4 @@
//go:build !debug && !profile
// +build !debug,!profile // +build !debug,!profile
package main package main

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package main package main

View File

@ -1,4 +1,5 @@
//+build !windows //go:build !windows
// +build !windows
package main package main

View File

@ -1,4 +1,5 @@
//+build windows //go:build windows
// +build windows
package main package main

1
go.mod
View File

@ -31,6 +31,7 @@ require (
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c 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 golang.org/x/text v0.3.6
google.golang.org/api v0.50.0 google.golang.org/api v0.50.0
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package archiver package archiver

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package archiver package archiver

View File

@ -1,3 +1,4 @@
//go:build aix || solaris
// +build aix solaris // +build aix solaris
package backend package backend

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package backend_test package backend_test

View File

@ -1,3 +1,4 @@
//go:build !aix && !solaris && !windows
// +build !aix,!solaris,!windows // +build !aix,!solaris,!windows
package backend package backend

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package local package local

View File

@ -22,7 +22,7 @@ type Cache struct {
free, size int // Current and max capacity, in bytes. 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 { func New(size int) *Cache {
c := &Cache{ c := &Cache{
free: size, free: size,

View File

@ -1,3 +1,4 @@
//go:build debug
// +build debug // +build debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build !debug
// +build !debug // +build !debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build debug
// +build debug // +build debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build !debug
// +build !debug // +build !debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build debug
// +build debug // +build debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build !debug
// +build !debug // +build !debug
package debug package debug

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package fs package fs

View File

@ -117,7 +117,7 @@ func (fs *LocalVss) snapshotPath(path string) string {
fs.msgMessage("creating VSS snapshot for [%s]\n", vssVolume) fs.msgMessage("creating VSS snapshot for [%s]\n", vssVolume)
if snapshot, err := NewVssSnapshot(vssVolume, 120, fs.msgError); err != nil { 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)) vssVolume, err))
fs.failedSnapshots[volumeNameLower] = struct{}{} fs.failedSnapshots[volumeNameLower] = struct{}{}
} else { } else {

View File

@ -1,3 +1,4 @@
//go:build freebsd || darwin || netbsd
// +build freebsd darwin netbsd // +build freebsd darwin netbsd
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build !windows && !darwin && !freebsd && !netbsd
// +build !windows,!darwin,!freebsd,!netbsd // +build !windows,!darwin,!freebsd,!netbsd
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package fs package fs

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package fuse package fuse

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package fuse package fuse

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package fuse package fuse

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package fuse package fuse

View File

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux
// +build darwin freebsd linux // +build darwin freebsd linux
package fuse package fuse

View File

@ -56,7 +56,7 @@ func TestRoundTripperReader(t *testing.T) {
_, err := io.ReadFull(rand.Reader, data) _, err := io.ReadFull(rand.Reader, data)
test.OK(t, err) test.OK(t, err)
var send *tracedReadCloser = newTracedReadCloser(bytes.NewReader(data)) send := newTracedReadCloser(bytes.NewReader(data))
var recv *tracedReadCloser var recv *tracedReadCloser
rt := limiter.Transport(roundTripper(func(req *http.Request) (*http.Response, error) { rt := limiter.Transport(roundTripper(func(req *http.Request) (*http.Response, error) {

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package restic package restic

View File

@ -1,3 +1,4 @@
//go:build !freebsd && !windows
// +build !freebsd,!windows // +build !freebsd,!windows
package restic package restic

View File

@ -166,7 +166,7 @@ func (node *Node) CreateAt(ctx context.Context, path string, repo Repository) er
case "socket": case "socket":
return nil return nil
default: default:
return errors.Errorf("filetype %q not implemented!\n", node.Type) return errors.Errorf("filetype %q not implemented", node.Type)
} }
return nil return nil

View File

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package restic package restic

View File

@ -1,3 +1,4 @@
//go:build freebsd
// +build freebsd // +build freebsd
package restic package restic

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package restic package restic

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package restic package restic

View File

@ -1,3 +1,4 @@
//go:build !linux && !darwin
// +build !linux,!darwin // +build !linux,!darwin
package restorer package restorer

View File

@ -1,4 +1,5 @@
//+build !windows //go:build !windows
// +build !windows
package restorer package restorer

View File

@ -61,7 +61,7 @@ func TestCounter(t *testing.T) {
func TestCounterNil(t *testing.T) { func TestCounterNil(t *testing.T) {
// Shouldn't panic. // Shouldn't panic.
var c *progress.Counter = nil var c *progress.Counter
c.Add(1) c.Add(1)
c.Done() c.Done()
} }

View File

@ -1,3 +1,4 @@
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
// +build darwin dragonfly freebsd netbsd openbsd // +build darwin dragonfly freebsd netbsd openbsd
package signals package signals

View File

@ -1,3 +1,4 @@
//go:build aix || linux || solaris
// +build aix linux solaris // +build aix linux solaris
package signals package signals

View File

@ -1,3 +1,4 @@
//go:build !linux
// +build !linux // +build !linux
package termstatus package termstatus

View File

@ -10,7 +10,7 @@ import (
"strings" "strings"
"unicode" "unicode"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
"golang.org/x/text/width" "golang.org/x/text/width"
) )
@ -321,7 +321,7 @@ func (t *Terminal) SetStatus(lines []string) {
var width int var width int
if t.canUpdateStatus { if t.canUpdateStatus {
var err error var err error
width, _, err = terminal.GetSize(int(t.fd)) width, _, err = term.GetSize(int(t.fd))
if err != nil || width <= 0 { if err != nil || width <= 0 {
// use 80 columns by default // use 80 columns by default
width = 80 width = 80

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package termstatus package termstatus
@ -6,7 +7,7 @@ import (
"io" "io"
"os" "os"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
) )
// clearCurrentLine removes all characters from the current line and resets the // 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 // CanUpdateStatus returns true if status lines can be printed, the process
// output is not redirected to a file or pipe. // output is not redirected to a file or pipe.
func CanUpdateStatus(fd uintptr) bool { func CanUpdateStatus(fd uintptr) bool {
if !terminal.IsTerminal(int(fd)) { if !term.IsTerminal(int(fd)) {
return false return false
} }
term := os.Getenv("TERM") term := os.Getenv("TERM")

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package termstatus package termstatus