Skip to content

Commit

Permalink
fix: 解决文件复制粘贴路径中带空格导致失败的问题 (#2883)
Browse files Browse the repository at this point in the history
Refs #2877
  • Loading branch information
zhengkunwang223 committed Nov 10, 2023
1 parent 8660ac6 commit 88ad8b1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/utils/files/file_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit 88ad8b1

Please sign in to comment.