Skip to content

Commit

Permalink
fix(dialect): 修正 mysql.Backup 可能漏掉的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed May 4, 2024
1 parent 89270e3 commit b203de5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dialect/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,13 @@ func (m *mysql) Backup(dsn, dest string) error {
return err
}

file, err := os.Create(dest)
output, err := os.Create(dest)
if err != nil {
return err
}
defer file.Close()
defer func() {
err = errors.Join(err, output.Close())
}()

cmd := newCommand("mysqldump", []string{}, []string{
buildCmdArgs("--host", h),
Expand All @@ -342,7 +344,8 @@ func (m *mysql) Backup(dsn, dest string) error {
conf.DBName,
})
cmd.Stderr = os.Stderr
cmd.Stdout = file
cmd.Stdout = output

return cmd.Run()
err = cmd.Run() // defer 需要用到
return err
}

0 comments on commit b203de5

Please sign in to comment.