From b203de560e67910752edf2da1f99deb053e1cf6c Mon Sep 17 00:00:00 2001 From: caixw Date: Sat, 4 May 2024 10:37:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(dialect):=20=E4=BF=AE=E6=AD=A3=20mysql.Back?= =?UTF-8?q?up=20=E5=8F=AF=E8=83=BD=E6=BC=8F=E6=8E=89=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialect/mysql.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dialect/mysql.go b/dialect/mysql.go index a70914a..7709d3a 100644 --- a/dialect/mysql.go +++ b/dialect/mysql.go @@ -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), @@ -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 }