Skip to content

Commit

Permalink
PMM-12460 Log error
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Nov 1, 2023
1 parent 534987e commit 282af8a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions managed/services/management/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ func (s *Service) UploadDump(_ context.Context, req *dumpv1beta1.UploadDumpReque
defer sftpClient.Close() //nolint:errcheck

for _, filePath := range filePaths {
if err = uploadFile(sftpClient, filePath, req.SftpParameters.Directory); err != nil {
if err = s.uploadFile(sftpClient, filePath, req.SftpParameters.Directory); err != nil {
return nil, errors.Wrap(err, "failed to upload file on SFTP server")
}
}

return &dumpv1beta1.UploadDumpResponse{}, nil
}

func uploadFile(client *sftp.Client, localFilePath, remoteDir string) error {
func (s *Service) uploadFile(client *sftp.Client, localFilePath, remoteDir string) error {
fileName := filepath.Base(localFilePath)
remoteFilePath := path.Join(remoteDir, fileName)

Expand All @@ -244,8 +244,11 @@ func uploadFile(client *sftp.Client, localFilePath, remoteDir string) error {
if err != nil {
return errors.Wrap(err, "failed to open dump file")
}
defer f.Close() //nolint:errcheck

defer func() {
if err := f.Close(); err != nil {
s.l.Errorf("Failed to close file: %+v", err)
}
}()
if _, err = bufio.NewReader(f).WriteTo(nf); err != nil {
return errors.Wrap(err, "failed to write dump file on SFTP server")
}
Expand Down

0 comments on commit 282af8a

Please sign in to comment.