Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:
with:
go-version: '1.23'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: latest
version: v2.1.2
- name: Build
run: go build -o dist/mysql-backup -v .
- name: vet
Expand Down
2 changes: 1 addition & 1 deletion cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dumpCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, er
cmdConfig.logger.Debug("starting dump")
defer func() {
tp := getTracerProvider()
tp.ForceFlush(ctx)
_ = tp.ForceFlush(ctx)
_ = tp.Shutdown(ctx)
}()
// check targets
Expand Down
2 changes: 1 addition & 1 deletion cmd/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func pruneCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, e
// this is the tracer that we will use throughout the entire run
defer func() {
tp := getTracerProvider()
tp.ForceFlush(ctx)
_ = tp.ForceFlush(ctx)
_ = tp.Shutdown(ctx)
}()
tracer := getTracer("prune")
Expand Down
2 changes: 1 addition & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
tracer := getTracer("restore")
defer func() {
tp := getTracerProvider()
tp.ForceFlush(ctx)
_ = tp.ForceFlush(ctx)
_ = tp.Shutdown(ctx)
}()
ctx = util.ContextWithTracer(ctx, tracer)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func rootCmd(execs execs) (*cobra.Command, error) {
if f, err = os.Open(configFilePath); err != nil {
return fmt.Errorf("fatal error config file: %w", err)
}
defer f.Close()
defer func() { _ = f.Close() }()
actualConfig, err = config.ProcessConfig(f)
if err != nil {
return fmt.Errorf("unable to read provided config: %w", err)
Expand Down
9 changes: 4 additions & 5 deletions pkg/archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ func Tar(src string, writer io.WriteCloser) error {
tw := tar.NewWriter(writer)
// defers are executed via a stack, so LIFO
// important we close the tw before the underlying writer
defer writer.Close()
defer tw.Close()
defer func() { _ = tw.Close(); _ = writer.Close() }()

// walk path
return filepath.Walk(src, func(file string, fi os.FileInfo, err error) error {
Expand All @@ -42,7 +41,7 @@ func Tar(src string, writer io.WriteCloser) error {
}

// update the name to correctly reflect the desired destination when untaring
header.Name = strings.TrimPrefix(strings.Replace(file, src, "", -1), string(filepath.Separator))
header.Name = strings.TrimPrefix(strings.ReplaceAll(file, src, ""), string(filepath.Separator))

// write the header
if err := tw.WriteHeader(header); err != nil {
Expand All @@ -62,7 +61,7 @@ func Tar(src string, writer io.WriteCloser) error {

// manually close here after each file operation; defering would cause each file close
// to wait until all operations have completed.
f.Close()
_ = f.Close()

return nil
})
Expand Down Expand Up @@ -121,7 +120,7 @@ func Untar(r io.Reader, dst string) error {

// manually close here after each file operation; defering would cause each file close
// to wait until all operations have completed.
f.Close()
_ = f.Close()
}
}
}
2 changes: 1 addition & 1 deletion pkg/config/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func getRemoteConfig(spec api.RemoteSpec) (conf api.Config, err error) {
if err != nil {
return conf, fmt.Errorf("error getting reader: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

// Read the body of the response and convert to a config.Config struct
var baseConf api.Config
Expand Down
8 changes: 4 additions & 4 deletions pkg/core/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e *Executor) Dump(ctx context.Context, opts DumpOptions) (DumpResults, err
if err != nil {
return results, fmt.Errorf("failed to make temporary working directory: %v", err)
}
defer os.RemoveAll(tmpdir)
defer func() { _ = os.RemoveAll(tmpdir) }()
// execute pre-backup scripts if any
if err := preBackup(ctx, timepart, path.Join(tmpdir, sourceFilename), tmpdir, opts.PreBackupScripts, logger.Level == log.DebugLevel); err != nil {
return results, fmt.Errorf("error running pre-restore: %v", err)
Expand All @@ -77,7 +77,7 @@ func (e *Executor) Dump(ctx context.Context, opts DumpOptions) (DumpResults, err
if err != nil {
return results, fmt.Errorf("failed to make temporary cache directory: %v", err)
}
defer os.RemoveAll(workdir)
defer func() { _ = os.RemoveAll(workdir) }()

dw := make([]database.DumpWriter, 0)

Expand Down Expand Up @@ -125,7 +125,7 @@ func (e *Executor) Dump(ctx context.Context, opts DumpOptions) (DumpResults, err
tarSpan.End()
return results, fmt.Errorf("failed to open output file '%s': %v", outFile, err)
}
defer f.Close()
defer func() { _ = f.Close() }()
cw, err := compressor.Compress(f)
if err != nil {
tarSpan.SetStatus(codes.Error, err.Error())
Expand All @@ -138,7 +138,7 @@ func (e *Executor) Dump(ctx context.Context, opts DumpOptions) (DumpResults, err
return results, fmt.Errorf("error creating the compressed archive: %v", err)
}
// we need to close it explicitly before moving ahead
f.Close()
defer func() { _ = f.Close() }()
tarSpan.SetStatus(codes.Ok, "completed")
tarSpan.End()

Expand Down
8 changes: 4 additions & 4 deletions pkg/core/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (e *Executor) Restore(ctx context.Context, opts RestoreOptions) error {
if err != nil {
return fmt.Errorf("unable to create temporary working directory: %v", err)
}
defer os.RemoveAll(tmpdir)
defer func() { _ = os.RemoveAll(tmpdir) }()
f, err := os.Open(tmpRestoreFile)
if f == nil {
return fmt.Errorf("unable to read the temporary download file: %v", err)
}
defer f.Close()
defer os.Remove(tmpRestoreFile)
defer func() { _ = f.Close() }()
defer func() { _ = os.Remove(tmpRestoreFile) }()

// create my tar reader to put the files in the directory
_, tarSpan := tracer.Start(ctx, "input_tar")
Expand Down Expand Up @@ -105,7 +105,7 @@ func (e *Executor) Restore(ctx context.Context, opts RestoreOptions) error {
if err != nil {
continue
}
defer file.Close()
defer func() { _ = file.Close() }()
readers = append(readers, file)
fileNames = append(fileNames, f.Name())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Dump(ctx context.Context, dbconn Connection, opts DumpOpts, writers []DumpW
if err != nil {
return fmt.Errorf("failed to open connection to database: %v", err)
}
defer db.Close()
defer func() { _ = db.Close() }()
for _, schema := range writer.Schemas {
dumper := &mysql.Data{
Out: writer.Writer,
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/mysql/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (data *Data) getTables() ([]Table, error) {
if err != nil {
return nil, err
}
defer rows.Close()
defer func() { _ = rows.Close() }()

for rows.Next() {
var tableName, tableType sql.NullString
Expand Down Expand Up @@ -302,7 +302,7 @@ func (data *Data) getCharsetCollections() error {
if err != nil {
return err
}
defer rows.Close()
defer func() { _ = rows.Close() }()

for rows.Next() {
var charset, collation sql.NullString
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/mysql/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (table *baseTable) initColumnData() error {
if err != nil {
return err
}
defer colInfo.Close()
defer func() { _ = colInfo.Close() }()

cols, err := colInfo.Columns()
if err != nil {
Expand Down Expand Up @@ -191,7 +191,7 @@ func (table *baseTable) Next() bool {
return false
}
} else {
table.rows.Close()
_ = table.rows.Close()
table.rows = nil
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Restore(ctx context.Context, dbconn Connection, databasesMap map[string]str
if err != nil {
return fmt.Errorf("failed to open connection to database: %v", err)
}
defer db.Close()
defer func() { _ = db.Close() }()

// load data into database by reading from each reader
for _, r := range readers {
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func GetSchemas(dbconn Connection) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("failed to open connection to database: %v", err)
}
defer db.Close()
defer func() { _ = db.Close() }()

// TODO: get list of schemas
// mysql -h $DB_SERVER -P $DB_PORT $DBUSER $DBPASS -N -e 'show databases'
rows, err := db.Query("show databases")
if err != nil {
return nil, fmt.Errorf("could not get schemas: %v", err)
}
defer rows.Close()
defer func() { _ = rows.Close() }()

names := []string{}
for rows.Next() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func copyFile(from, to string) (int64, error) {
if err != nil {
return 0, fmt.Errorf("failed to open source file %s: %w", from, err)
}
defer src.Close()
defer func() { _ = src.Close() }()

dst, err := os.Create(to)
if err != nil {
return 0, fmt.Errorf("failed to create target file %s: %w", to, err)
}
defer dst.Close()
defer func() { _ = dst.Close() }()
n, err := io.Copy(dst, src)
return n, err
}
4 changes: 2 additions & 2 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry)
if err != nil {
return 0, fmt.Errorf("failed to create target restore file %q, %v", target, err)
}
defer f.Close()
defer func() { _ = f.Close() }()

// Write the contents of S3 Object to the file
n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{
Expand Down Expand Up @@ -112,7 +112,7 @@ func (s *S3) Push(ctx context.Context, target, source string, logger *log.Entry)
if err != nil {
return 0, fmt.Errorf("failed to read input file %q, %v", source, err)
}
defer f.Close()
defer func() { _ = f.Close() }()
countingReader := NewCountingReader(f)

// S3 always prepends a /, so if it already has one, it would become //
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func (s *SMB) Pull(ctx context.Context, source, target string, logger *log.Entry
if err != nil {
return err
}
defer to.Close()
defer func() { _ = to.Close() }()
from, err := fs.Open(smbFilename)
if err != nil {
return err
}
defer from.Close()
defer func() { _ = from.Close() }()
copied, err = io.Copy(to, from)
return err
})
Expand All @@ -88,12 +88,12 @@ func (s *SMB) Push(ctx context.Context, target, source string, logger *log.Entry
if err != nil {
return err
}
defer from.Close()
defer func() { _ = from.Close() }()
to, err := fs.Create(smbFilename)
if err != nil {
return err
}
defer to.Close()
defer func() { _ = to.Close() }()
copied, err = io.Copy(to, from)
return err
})
Expand Down Expand Up @@ -156,7 +156,7 @@ func (s *SMB) exec(u url.URL, command func(fs *smb2.Share, sharepath string) err
if err != nil {
return err
}
defer conn.Close()
defer func() { _ = conn.Close() }()

d := &smb2.Dialer{
Initiator: &smb2.NTLMInitiator{
Expand Down