diff --git a/cmd/backup/archive.go b/cmd/backup/archive.go index abc61296..6f3af0a6 100644 --- a/cmd/backup/archive.go +++ b/cmd/backup/archive.go @@ -8,6 +8,7 @@ package main import ( "archive/tar" + "errors" "fmt" "io" "os" @@ -164,7 +165,7 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) (returnErr return } defer func() { - returnErr = file.Close() + returnErr = errors.Join(returnErr, file.Close()) }() _, err = io.Copy(tarWriter, file) diff --git a/internal/storage/dropbox/dropbox.go b/internal/storage/dropbox/dropbox.go index b6585318..e50643b9 100644 --- a/internal/storage/dropbox/dropbox.go +++ b/internal/storage/dropbox/dropbox.go @@ -3,6 +3,7 @@ package dropbox import ( "bytes" "context" + "errors" "fmt" "net/url" "os" @@ -111,7 +112,7 @@ func (b *dropboxStorage) Copy(file string) (returnErr error) { return } defer func() { - returnErr = r.Close() + returnErr = errors.Join(returnErr, r.Close()) }() // Start new upload session and get session id diff --git a/internal/storage/googledrive/googledrive.go b/internal/storage/googledrive/googledrive.go index aff38362..e558d3eb 100644 --- a/internal/storage/googledrive/googledrive.go +++ b/internal/storage/googledrive/googledrive.go @@ -5,6 +5,7 @@ package googledrive import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -97,7 +98,7 @@ func (b *googleDriveStorage) Copy(file string) (returnErr error) { return } defer func() { - returnErr = f.Close() + returnErr = errors.Join(returnErr, f.Close()) }() driveFile := &drive.File{Name: name} diff --git a/internal/storage/local/local.go b/internal/storage/local/local.go index 0f80ece1..3a803425 100644 --- a/internal/storage/local/local.go +++ b/internal/storage/local/local.go @@ -155,7 +155,7 @@ func copyFile(src, dst string) (returnErr error) { return } defer func() { - returnErr = in.Close() + returnErr = errors.Join(returnErr, in.Close()) }() out, err := os.Create(dst) diff --git a/internal/storage/ssh/ssh.go b/internal/storage/ssh/ssh.go index a87bf78e..9047d9b4 100644 --- a/internal/storage/ssh/ssh.go +++ b/internal/storage/ssh/ssh.go @@ -110,7 +110,8 @@ func (b *sshStorage) Name() string { // Copy copies the given file to the SSH storage backend. func (b *sshStorage) Copy(file string) (returnErr error) { if err := b.sftpClient.MkdirAll(b.DestinationPath); err != nil { - return errwrap.Wrap(err, "error ensuring destination directory") + returnErr = errwrap.Wrap(err, "error ensuring destination directory") + return } source, err := os.Open(file) @@ -120,7 +121,7 @@ func (b *sshStorage) Copy(file string) (returnErr error) { return } defer func() { - returnErr = source.Close() + returnErr = errors.Join(returnErr, source.Close()) }() destination, err := b.sftpClient.Create(path.Join(b.DestinationPath, name)) @@ -129,7 +130,7 @@ func (b *sshStorage) Copy(file string) (returnErr error) { return } defer func() { - returnErr = destination.Close() + returnErr = errors.Join(returnErr, destination.Close()) }() chunk := make([]byte, 1e9)