From 548d741f03bfe2fe7a8d7792cff053276c03ba86 Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Fri, 25 Aug 2023 19:12:32 +0200 Subject: [PATCH] Fix lint warnings and std lib deprecations --- cmd/backup/config.go | 3 +-- cmd/backup/exec.go | 11 ++++++----- cmd/backup/lock.go | 4 +++- cmd/backup/script.go | 1 + internal/storage/ssh/ssh.go | 3 +-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/backup/config.go b/cmd/backup/config.go index b7ea5d1..857b6ea 100644 --- a/cmd/backup/config.go +++ b/cmd/backup/config.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "os" "regexp" "strconv" @@ -115,7 +114,7 @@ func (c *CertDecoder) Decode(v string) error { if v == "" { return nil } - content, err := ioutil.ReadFile(v) + content, err := os.ReadFile(v) if err != nil { content = []byte(v) } diff --git a/cmd/backup/exec.go b/cmd/backup/exec.go index 110eaec..91f4dec 100644 --- a/cmd/backup/exec.go +++ b/cmd/backup/exec.go @@ -10,7 +10,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -57,13 +57,14 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte, return nil, nil, fmt.Errorf("exec: error demultiplexing output: %w", err) } break + default: } - stdout, err := ioutil.ReadAll(&outBuf) + stdout, err := io.ReadAll(&outBuf) if err != nil { return nil, nil, fmt.Errorf("exec: error reading stdout: %w", err) } - stderr, err := ioutil.ReadAll(&errBuf) + stderr, err := io.ReadAll(&errBuf) if err != nil { return nil, nil, fmt.Errorf("exec: error reading stderr: %w", err) } @@ -152,9 +153,9 @@ func (s *script) runLabeledCommands(label string) error { g.Go(func() error { cmd, ok := c.Labels[label] if !ok && label == "docker-volume-backup.archive-pre" { - cmd, _ = c.Labels["docker-volume-backup.exec-pre"] + cmd = c.Labels["docker-volume-backup.exec-pre"] } else if !ok && label == "docker-volume-backup.archive-post" { - cmd, _ = c.Labels["docker-volume-backup.exec-post"] + cmd = c.Labels["docker-volume-backup.exec-post"] } userLabelName := fmt.Sprintf("%s.user", label) diff --git a/cmd/backup/lock.go b/cmd/backup/lock.go index 6bab09a..2d4701a 100644 --- a/cmd/backup/lock.go +++ b/cmd/backup/lock.go @@ -15,10 +15,12 @@ import ( // caller invokes the returned release func. In case the lock is currently blocked // by another execution, it will repeatedly retry until the lock is available // or the given timeout is exceeded. +// +//lint:ignore U1000 Keep unused function func (s *script) lock(lockfile string) (func() error, error) { start := time.Now() defer func() { - s.stats.LockedTime = time.Now().Sub(start) + s.stats.LockedTime = time.Since(start) }() retry := time.NewTicker(5 * time.Second) diff --git a/cmd/backup/script.go b/cmd/backup/script.go index a80332a..972b4d7 100644 --- a/cmd/backup/script.go +++ b/cmd/backup/script.go @@ -53,6 +53,7 @@ type script struct { file string stats *Stats + //lint:ignore U1000 used in lock.go encounteredLock bool c *Config diff --git a/internal/storage/ssh/ssh.go b/internal/storage/ssh/ssh.go index 14331c5..21a1e10 100644 --- a/internal/storage/ssh/ssh.go +++ b/internal/storage/ssh/ssh.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -46,7 +45,7 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error } if _, err := os.Stat(opts.IdentityFile); err == nil { - key, err := ioutil.ReadFile(opts.IdentityFile) + key, err := os.ReadFile(opts.IdentityFile) if err != nil { return nil, errors.New("NewStorageBackend: error reading the private key") }