Skip to content

Commit

Permalink
Add diff to CreateRepo()
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Oct 5, 2023
1 parent adea9ad commit a45cf55
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ casdoorOrganization = "casbin"
casdoorApplication = "app-casibase"
isDemoMode = false
appDir = "C:/github_repos"
dbPass = ""
31 changes: 25 additions & 6 deletions object/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Site struct {

Domain string `xorm:"varchar(100)" json:"domain"`
Host string `xorm:"varchar(100)" json:"host"`
Port int `json:"port"`
SslMode string `xorm:"varchar(100)" json:"sslMode"`
SslCert string `xorm:"varchar(100)" json:"sslCert"`
PublicIp string `xorm:"varchar(100)" json:"publicIp"`
Expand Down Expand Up @@ -188,35 +189,53 @@ func (site *Site) GetId() string {
return fmt.Sprintf("%s/%s", site.Owner, site.Name)
}

func (site *Site) GetHost() string {
if site.Host != "" {
return site.Host
}

if site.Port == 0 {
return ""
}

res := fmt.Sprintf("http://localhost:%d", site.Port)
return res
}

func (site *Site) checkNodes() {
hostname := util.GetHostname()
for i, node := range site.Nodes {
if node.Name != hostname {
continue
}

if site.Host == "" {
if site.GetHost() == "" {
continue
}

ok, msg := pingUrl(site.Host)
ok, msg := pingUrl(site.GetHost())
status := "Running"
if !ok {
status = "Stopped"
}

run.CreateRepo(site.Name)
diff := ""
if i != 0 {
diff = site.Nodes[0].Diff
}

run.CreateRepo(site.Name, !ok, diff)

version := getSiteVersion(site.Name)

path := run.GetRepoPath(site.Name)
diff := run.GitDiff(path)
newDiff := run.GitDiff(path)

if node.Status != status || node.Message != msg || node.Version != version || node.Diff != diff {
if node.Status != status || node.Message != msg || node.Version != version || node.Diff != newDiff {
site.Nodes[i].Status = status
site.Nodes[i].Message = msg
site.Nodes[i].Version = version
site.Nodes[i].Diff = diff
site.Nodes[i].Diff = newDiff
UpdateSite(site.GetId(), site)
}
}
Expand Down
2 changes: 1 addition & 1 deletion run/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func TestGitGetDiff(t *testing.T) {
//diff := GitDiff("F:/github_repos/casdoor")
//println(diff)

CreateRepo("casdoor_test", true)
CreateRepo("casdoor_test", true, "")
}
8 changes: 3 additions & 5 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/casbin/caswaf/util"
)

func CreateRepo(siteName string, needStart bool) {
func CreateRepo(siteName string, needStart bool, diff string) {
path := GetRepoPath(siteName)
if !util.FileExist(path) {
originalName := getOriginalName(siteName)
Expand All @@ -30,10 +30,8 @@ func CreateRepo(siteName string, needStart bool) {
if strings.HasPrefix(siteName, "cc_") || strings.Count(siteName, "_") == 2 {
index := getNameIndex(siteName)
updateAppConfFile(siteName, index)
} else if originalName != siteName {
originalPath := GetRepoPath(originalName)
patch := GitDiff(originalPath)
gitApply(path, patch)
} else if diff != "" {
gitApply(path, diff)
}
}

Expand Down
14 changes: 6 additions & 8 deletions run/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package run

import (
"bytes"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -103,16 +102,15 @@ func startProcess(name string) {
}
}

func isProcessActive(name string) bool {
func stopProcess(name string) {
fmt.Printf("Stopping process: [%s]\n", name)

windowName := fmt.Sprintf("%s.bat - Shortcut", name)
cmd := exec.Command("cmd", "/C", "tasklist", "/v", "|", "findstr", windowName)
var out bytes.Buffer
cmd.Stdout = &out
// taskkill /IM "casdoor.bat - Shortcut" /F
// taskkill /F /FI "WINDOWTITLE eq casdoor.bat - Shortcut" /T
cmd := exec.Command("taskkill", "/F", "/FI", fmt.Sprintf("WINDOWTITLE eq %s", windowName), "/T")
err := cmd.Run()
if err != nil {
panic(err)
}

res := out.String() != ""
return res
}

0 comments on commit a45cf55

Please sign in to comment.