Skip to content

Commit

Permalink
Improve CreateRepo() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Oct 10, 2023
1 parent aaab8f5 commit 2785fb8
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"github.com/casbin/caswaf/util"
)

func isTargetRepo(siteName string) bool {
return strings.HasPrefix(siteName, "cc_") || strings.Count(siteName, "_") == 2
}

func CreateRepo(siteName string, needStart bool, diff string) (int, error) {
path := GetRepoPath(siteName)
if !util.FileExist(path) {
Expand All @@ -40,21 +44,25 @@ func CreateRepo(siteName string, needStart bool, diff string) (int, error) {
}
}

if strings.HasPrefix(siteName, "cc_") || strings.Count(siteName, "_") == 2 {
needWebBuild := false
if isTargetRepo(siteName) {
index := getNameIndex(siteName)
updateAppConfFile(siteName, index)
if index == 0 {
err = gitWebBuild(path)
needWebBuild = true
}
} else {
needWebBuild = true

if diff != "" {
err = gitApply(path, diff)
if err != nil {
return 0, err
}
}
} else if diff != "" {
err = gitApply(path, diff)
if err != nil {
return 0, err
}
}

if needWebBuild {
err = gitWebBuild(path)
if err != nil {
return 0, err
Expand All @@ -75,12 +83,39 @@ func CreateRepo(siteName string, needStart bool, diff string) (int, error) {
if err != nil {
return 0, err
}

needWebBuild := false
if affected {
if isTargetRepo(siteName) {
index := getNameIndex(siteName)
if index == 0 {
needWebBuild = true
}
} else {
needWebBuild = true
}
} else {
webIndex := filepath.Join(path, "web/build/index.html")
if !util.FileExist(webIndex) {
needWebBuild = true
}

if isTargetRepo(siteName) {
index := getNameIndex(siteName)
if index != 0 {
needWebBuild = false
}
}
}

if needWebBuild {
err = gitWebBuild(path)
if err != nil {
return 0, err
}
}

if affected {
if !needStart {
err = stopProcess(siteName)
if err != nil {
Expand All @@ -100,24 +135,6 @@ func CreateRepo(siteName string, needStart bool, diff string) (int, error) {

return pid, nil
}
} else {
webIndex := filepath.Join(path, "web/build/index.html")
if !util.FileExist(webIndex) {
if strings.HasPrefix(siteName, "cc_") || strings.Count(siteName, "_") == 2 {
index := getNameIndex(siteName)
if index == 0 {
err = gitWebBuild(path)
if err != nil {
return 0, err
}
}
} else {
err = gitWebBuild(path)
if err != nil {
return 0, err
}
}
}
}
}

Expand Down

0 comments on commit 2785fb8

Please sign in to comment.