Skip to content

Commit 24c4774

Browse files
authored
代码打包的插件,从后台安装失败,认不到目录的问题 (#1634)
#1633
1 parent 4890de5 commit 24c4774

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

server/service/system/sys_auto_code.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"mime/multipart"
1010
"os"
11+
"path"
1112
"path/filepath"
1213
"strconv"
1314
"strings"
@@ -739,36 +740,44 @@ func (autoCodeService *AutoCodeService) InstallPlugin(file *multipart.FileHeader
739740
paths = filterFile(paths)
740741
var webIndex = -1
741742
var serverIndex = -1
743+
webPlugin := ""
744+
serverPlugin := ""
745+
742746
for i := range paths {
743747
paths[i] = filepath.ToSlash(paths[i])
744748
pathArr := strings.Split(paths[i], "/")
745749
ln := len(pathArr)
746-
if ln < 2 {
750+
751+
if ln < 4 {
747752
continue
748753
}
749-
if pathArr[ln-2] == "server" && pathArr[ln-1] == "plugin" {
750-
serverIndex = i
754+
if pathArr[2]+"/"+pathArr[3] == `server/plugin` && len(serverPlugin) == 0 {
755+
serverPlugin = path.Join(pathArr[0], pathArr[1], pathArr[2], pathArr[3])
751756
}
752-
if pathArr[ln-2] == "web" && pathArr[ln-1] == "plugin" {
753-
webIndex = i
757+
if pathArr[2]+"/"+pathArr[3] == `web/plugin` && len(webPlugin) == 0 {
758+
webPlugin = path.Join(pathArr[0], pathArr[1], pathArr[2], pathArr[3])
754759
}
755760
}
756-
if webIndex == -1 && serverIndex == -1 {
761+
if len(serverPlugin) == 0 && len(webPlugin) == 0 {
757762
zap.L().Error("非标准插件,请按照文档自动迁移使用")
758763
return webIndex, serverIndex, errors.New("非标准插件,请按照文档自动迁移使用")
759764
}
760765

761-
if webIndex != -1 {
762-
err = installation(paths[webIndex], global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.Web)
766+
if len(serverPlugin) != 0 {
767+
err = installation(serverPlugin, global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.Server)
763768
if err != nil {
764769
return webIndex, serverIndex, err
765770
}
766771
}
767772

768-
if serverIndex != -1 {
769-
err = installation(paths[serverIndex], global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.Server)
773+
if len(webPlugin) != 0 {
774+
err = installation(webPlugin, global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.Web)
775+
if err != nil {
776+
return webIndex, serverIndex, err
777+
}
770778
}
771-
return webIndex, serverIndex, err
779+
780+
return 1, 1, err
772781
}
773782

774783
func installation(path string, formPath string, toPath string) error {

0 commit comments

Comments
 (0)