Skip to content

Commit b947f04

Browse files
author
v_zhibsong
committed
change2
1 parent ebd515f commit b947f04

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

server/utils/file_operations.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package utils
22

33
import (
4-
"errors"
54
"os"
65
"path/filepath"
76
)
@@ -21,9 +20,18 @@ func FileMove(src string, dst string) (err error) {
2120
if err != nil {
2221
return err
2322
}
24-
if !filepath.IsAbs(dst) && !filepath.IsAbs(src) {
25-
return errors.New(dst + " or " + src + " path is not abs")
23+
var revoke = false
24+
Redirect:
25+
_, err = os.Stat(filepath.Dir(dst))
26+
if err != nil {
27+
err = os.MkdirAll(filepath.Dir(dst), 0755)
28+
if err != nil {
29+
return err
30+
}
31+
if !revoke {
32+
revoke = true
33+
goto Redirect
34+
}
2635
}
27-
// TODO 判断文件夹是否存在,不存在mkdir
2836
return os.Rename(src, dst)
29-
}
37+
}

0 commit comments

Comments
 (0)