From 7c9608727dcc4ebdd30f7d9bf5e0128f370edc0c Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:09:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#4419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/common/common.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index e65c203df..10e320fc6 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -94,14 +94,16 @@ func CopyFile(src, dst string) error { if path.Base(src) != path.Base(dst) { dst = path.Join(dst, path.Base(src)) } - dest, err := os.Create(dst) + target, err := os.OpenFile(dst+"_temp", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return err } - defer dest.Close() + defer target.Close() - _, err = io.Copy(dest, source) - if err != nil { + if _, err = io.Copy(target, source); err != nil { + return err + } + if err = os.Rename(dst+"_temp", dst); err != nil { return err } return nil