From f211b6b5aee424556198fddc7f88bda9499815d9 Mon Sep 17 00:00:00 2001 From: Node <8974108+qwenode@users.noreply.github.com> Date: Thu, 23 May 2024 16:41:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=87=A0=E5=A4=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E6=9C=AA=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/runtime_utils.go | 1 + backend/utils/mysql/client/local.go | 5 ++++- backend/utils/mysql/client/remote.go | 5 ++++- backend/utils/postgresql/client/local.go | 5 ++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/app/service/runtime_utils.go b/backend/app/service/runtime_utils.go index 31ffa6a0a..f24a080de 100644 --- a/backend/app/service/runtime_utils.go +++ b/backend/app/service/runtime_utils.go @@ -150,6 +150,7 @@ func runComposeCmdWithLog(operate string, composePath string, logPath string) er global.LOG.Errorf("Failed to open log file: %v", err) return err } + defer logFile.Close() multiWriterStdout := io.MultiWriter(os.Stdout, logFile) cmd.Stdout = multiWriterStdout var stderrBuf bytes.Buffer diff --git a/backend/utils/mysql/client/local.go b/backend/utils/mysql/client/local.go index c02d644a6..5e5fe7e57 100644 --- a/backend/utils/mysql/client/local.go +++ b/backend/utils/mysql/client/local.go @@ -224,7 +224,10 @@ func (r *Local) Backup(info BackupInfo) error { return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) } } - outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + if err == nil { + defer outfile.Close() + } dumpCmd := "mysqldump" if r.Type == constant.AppMariaDB { dumpCmd = "mariadb-dump" diff --git a/backend/utils/mysql/client/remote.go b/backend/utils/mysql/client/remote.go index 9a9b62e73..17ea7029f 100644 --- a/backend/utils/mysql/client/remote.go +++ b/backend/utils/mysql/client/remote.go @@ -235,7 +235,10 @@ func (r *Remote) Backup(info BackupInfo) error { return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) } } - outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + if err == nil { + defer outfile.Close() + } dumpCmd := "mysqldump" if r.Type == constant.AppMariaDB { dumpCmd = "mariadb-dump" diff --git a/backend/utils/postgresql/client/local.go b/backend/utils/postgresql/client/local.go index 98bb44e67..4b927e78c 100644 --- a/backend/utils/postgresql/client/local.go +++ b/backend/utils/postgresql/client/local.go @@ -129,7 +129,10 @@ func (r *Local) Backup(info BackupInfo) error { return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) } } - outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) + if err == nil { + defer outfile.Close() + } global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName) cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name) gzipCmd := exec.Command("gzip", "-cf")