mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-06-19 17:17:50 +02:00
Defer statements could possibly void stored error values (#798)
This commit is contained in:
1 parent
d5a5746f17
commit
10f588dbc6
5 files changed
+11
-7
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user