From 88ad8b1b71a0a8cc23af976d5545472025e50cee Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:38:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4=E8=B7=AF=E5=BE=84=E4=B8=AD?= =?UTF-8?q?=E5=B8=A6=E7=A9=BA=E6=A0=BC=E5=AF=BC=E8=87=B4=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#2883)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/2877 --- backend/utils/files/file_op.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index 3f95b4ac8..ca7f91092 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -299,7 +299,8 @@ func (f FileOp) Cut(oldPaths []string, dst, name string, cover bool) error { if cover { coverFlag = "-f" } - cmdStr := fmt.Sprintf("mv %s %s %s", coverFlag, p, dstPath) + + cmdStr := fmt.Sprintf(`mv %s "%s" "%s"`, coverFlag, p, dstPath) if err := cmd.ExecCmd(cmdStr); err != nil { return err } @@ -362,13 +363,13 @@ func (f FileOp) CopyAndReName(src, dst, name string, cover bool) error { if name != "" && !cover { dstPath = filepath.Join(dst, name) } - return cmd.ExecCmd(fmt.Sprintf("cp -rf %s %s", src, dstPath)) + return cmd.ExecCmd(fmt.Sprintf(`cp -rf "%s" "%s"`, src, dstPath)) } else { dstPath := filepath.Join(dst, name) if cover { dstPath = dst } - return cmd.ExecCmd(fmt.Sprintf("cp -f %s %s", src, dstPath)) + return cmd.ExecCmd(fmt.Sprintf(`cp -f "%s" "%s"`, src, dstPath)) } } @@ -381,11 +382,12 @@ func (f FileOp) CopyDir(src, dst string) error { if err = f.Fs.MkdirAll(dstDir, srcInfo.Mode()); err != nil { return err } - return cmd.ExecCmd(fmt.Sprintf("cp -rf %s %s", src, dst+"/")) + return cmd.ExecCmd(fmt.Sprintf(`cp -rf "%s" "%s"`, src, dst+"/")) } func (f FileOp) CopyFile(src, dst string) error { - return cmd.ExecCmd(fmt.Sprintf("cp -f %s %s", src, dst+"/")) + dst = filepath.Clean(dst) + string(filepath.Separator) + return cmd.ExecCmd(fmt.Sprintf(`cp -f "%s" "%s"`, src, dst+"/")) } func (f FileOp) GetDirSize(path string) (float64, error) {