Skip to content

Commit

Permalink
Reduce updateShortcutFile() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Oct 10, 2023
1 parent 299c417 commit 82ea5e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ func CreateRepo(siteName string, needStart bool, diff string, providerName strin
}
}

err = updateBatFile(siteName)
batExisted, err := updateBatFile(siteName)
if err != nil {
return 0, err
}

err = updateShortcutFile(siteName)
if err != nil {
return 0, err
if !batExisted {
err = updateShortcutFile(siteName)
if err != nil {
return 0, err
}
}
} else {
affected, err := gitPull(path)
Expand Down
10 changes: 6 additions & 4 deletions run/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ func InitSelfStart() {
panic("InitSelfStart() error, siteName should not be empty")
}

err := updateBatFile(siteName)
batExisted, err := updateBatFile(siteName)
if err != nil {
panic(err)
}

err = updateShortcutFile(siteName)
if err != nil {
panic(err)
if !batExisted {
err = updateShortcutFile(siteName)
if err != nil {
panic(err)
}
}
}
11 changes: 8 additions & 3 deletions run/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,22 @@ func updateAppConfFile(name string, i int) {
util.WriteStringToPath(content, confPath)
}

func updateBatFile(name string) error {
func updateBatFile(name string) (bool, error) {
fmt.Printf("updateBatFile(): [%s]\n", name)

batPath := getBatPath(name)
err := ensureFileFolderExists(filepath.Dir(batPath))
if err != nil {
return err
return false, err
}

if util.FileExist(batPath) {
return true, nil
}

content := fmt.Sprintf("cd %s\ngo run main.go", GetRepoPath(name))
util.WriteStringToPath(content, batPath)
return nil
return false, nil
}

func updateShortcutFile(name string) error {
Expand Down

0 comments on commit 82ea5e2

Please sign in to comment.