Fix lint warnings and std lib deprecations

This commit is contained in:
MaxJa4 2023-08-25 19:12:32 +02:00
parent 3d7677f02a
commit 548d741f03
5 changed files with 12 additions and 10 deletions

View File

@ -7,7 +7,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
@ -115,7 +114,7 @@ func (c *CertDecoder) Decode(v string) error {
if v == "" { if v == "" {
return nil return nil
} }
content, err := ioutil.ReadFile(v) content, err := os.ReadFile(v)
if err != nil { if err != nil {
content = []byte(v) content = []byte(v)
} }

View File

@ -10,7 +10,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"strings" "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) return nil, nil, fmt.Errorf("exec: error demultiplexing output: %w", err)
} }
break break
default:
} }
stdout, err := ioutil.ReadAll(&outBuf) stdout, err := io.ReadAll(&outBuf)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("exec: error reading stdout: %w", err) return nil, nil, fmt.Errorf("exec: error reading stdout: %w", err)
} }
stderr, err := ioutil.ReadAll(&errBuf) stderr, err := io.ReadAll(&errBuf)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("exec: error reading stderr: %w", err) 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 { g.Go(func() error {
cmd, ok := c.Labels[label] cmd, ok := c.Labels[label]
if !ok && label == "docker-volume-backup.archive-pre" { 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" { } 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) userLabelName := fmt.Sprintf("%s.user", label)

View File

@ -15,10 +15,12 @@ import (
// caller invokes the returned release func. In case the lock is currently blocked // 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 // by another execution, it will repeatedly retry until the lock is available
// or the given timeout is exceeded. // or the given timeout is exceeded.
//
//lint:ignore U1000 Keep unused function
func (s *script) lock(lockfile string) (func() error, error) { func (s *script) lock(lockfile string) (func() error, error) {
start := time.Now() start := time.Now()
defer func() { defer func() {
s.stats.LockedTime = time.Now().Sub(start) s.stats.LockedTime = time.Since(start)
}() }()
retry := time.NewTicker(5 * time.Second) retry := time.NewTicker(5 * time.Second)

View File

@ -53,6 +53,7 @@ type script struct {
file string file string
stats *Stats stats *Stats
//lint:ignore U1000 used in lock.go
encounteredLock bool encounteredLock bool
c *Config c *Config

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -46,7 +45,7 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
} }
if _, err := os.Stat(opts.IdentityFile); err == nil { if _, err := os.Stat(opts.IdentityFile); err == nil {
key, err := ioutil.ReadFile(opts.IdentityFile) key, err := os.ReadFile(opts.IdentityFile)
if err != nil { if err != nil {
return nil, errors.New("NewStorageBackend: error reading the private key") return nil, errors.New("NewStorageBackend: error reading the private key")
} }