mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-04-15 13:45:35 +02:00
Update golangci integration (#637)
* Update golangci integration * Fix newly discovered errcheck complaints * Increase timeout value
This commit is contained in:
@@ -121,10 +121,11 @@ func getCompressionWriter(file *os.File, algo string, concurrency int) (io.Write
|
||||
}
|
||||
}
|
||||
|
||||
func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
|
||||
func writeTarball(path string, tarWriter *tar.Writer, prefix string) (returnErr error) {
|
||||
fileInfo, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, fmt.Sprintf("error getting file info for %s", path))
|
||||
returnErr = errwrap.Wrap(err, fmt.Sprintf("error getting file info for %s", path))
|
||||
return
|
||||
}
|
||||
|
||||
if fileInfo.Mode()&os.ModeSocket == os.ModeSocket {
|
||||
@@ -135,19 +136,22 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
|
||||
if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||
var err error
|
||||
if link, err = os.Readlink(path); err != nil {
|
||||
return errwrap.Wrap(err, fmt.Sprintf("error resolving symlink %s", path))
|
||||
returnErr = errwrap.Wrap(err, fmt.Sprintf("error resolving symlink %s", path))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
header, err := tar.FileInfoHeader(fileInfo, link)
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, "error getting file info header")
|
||||
returnErr = errwrap.Wrap(err, "error getting file info header")
|
||||
return
|
||||
}
|
||||
header.Name = strings.TrimPrefix(path, prefix)
|
||||
|
||||
err = tarWriter.WriteHeader(header)
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, "error writing file info header")
|
||||
returnErr = errwrap.Wrap(err, "error writing file info header")
|
||||
return
|
||||
}
|
||||
|
||||
if !fileInfo.Mode().IsRegular() {
|
||||
@@ -156,13 +160,17 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
|
||||
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, fmt.Sprintf("error opening %s", path))
|
||||
returnErr = errwrap.Wrap(err, fmt.Sprintf("error opening %s", path))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
returnErr = file.Close()
|
||||
}()
|
||||
|
||||
_, err = io.Copy(tarWriter, file)
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, fmt.Sprintf("error copying %s to tar writer", path))
|
||||
returnErr = errwrap.Wrap(err, fmt.Sprintf("error copying %s to tar writer", path))
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -153,13 +153,13 @@ func source(path string) (map[string]string, error) {
|
||||
currentValue, currentOk := os.LookupEnv(key)
|
||||
defer func() {
|
||||
if currentOk {
|
||||
os.Setenv(key, currentValue)
|
||||
_ = os.Setenv(key, currentValue)
|
||||
return
|
||||
}
|
||||
os.Unsetenv(key)
|
||||
_ = os.Unsetenv(key)
|
||||
}()
|
||||
result[key] = value
|
||||
os.Setenv(key, value)
|
||||
_ = os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
|
||||
@@ -60,8 +60,10 @@ func TestSource(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
os.Setenv("QUX", "yyy")
|
||||
defer os.Unsetenv("QUX")
|
||||
_ = os.Setenv("QUX", "yyy")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("QUX")
|
||||
}()
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
@@ -177,8 +177,12 @@ func (s *script) runLabeledCommands(label string) error {
|
||||
s.logger.Info(fmt.Sprintf("Running %s command %s for container %s", label, cmd, strings.TrimPrefix(c.Names[0], "/")))
|
||||
stdout, stderr, err := s.exec(c.ID, cmd, user)
|
||||
if s.c.ExecForwardOutput {
|
||||
os.Stderr.Write(stderr)
|
||||
os.Stdout.Write(stdout)
|
||||
if _, err := os.Stderr.Write(stderr); err != nil {
|
||||
return errwrap.Wrap(err, "error writing to stderr")
|
||||
}
|
||||
if _, err := os.Stdout.Write(stdout); err != nil {
|
||||
return errwrap.Wrap(err, "error writing to stdout")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return errwrap.Wrap(err, "error executing command")
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/docker/cli/cli/command/service/progress"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
ctr "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
@@ -66,7 +65,7 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
|
||||
),
|
||||
)
|
||||
case <-poll.C:
|
||||
containers, err := cli.ContainerList(context.Background(), container.ListOptions{
|
||||
containers, err := cli.ContainerList(context.Background(), ctr.ListOptions{
|
||||
Filters: filters.NewArgs(filters.KeyValuePair{
|
||||
Key: "label",
|
||||
Value: fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID),
|
||||
@@ -124,11 +123,11 @@ func (s *script) stopContainersAndServices() (func() error, error) {
|
||||
labelValue,
|
||||
)
|
||||
|
||||
allContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{})
|
||||
allContainers, err := s.cli.ContainerList(context.Background(), ctr.ListOptions{})
|
||||
if err != nil {
|
||||
return noop, errwrap.Wrap(err, "error querying for containers")
|
||||
}
|
||||
containersToStop, err := s.cli.ContainerList(context.Background(), container.ListOptions{
|
||||
containersToStop, err := s.cli.ContainerList(context.Background(), ctr.ListOptions{
|
||||
Filters: filters.NewArgs(filters.KeyValuePair{
|
||||
Key: "label",
|
||||
Value: filterMatchLabel,
|
||||
@@ -215,7 +214,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
|
||||
)
|
||||
}
|
||||
|
||||
var stoppedContainers []container.Summary
|
||||
var stoppedContainers []ctr.Summary
|
||||
var stopErrors []error
|
||||
for _, container := range containersToStop {
|
||||
if err := s.cli.ContainerStop(context.Background(), container.ID, ctr.StopOptions{}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user