summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2020-01-09 00:22:37 -0600
committerLauris BH <lauris@nix.lv>2020-01-09 08:22:37 +0200
commitee9ce0cfa9c003b359d2d3fba9346fd0929e88f4 (patch)
tree75417b00a53bdfd3526f96f109b851d9316ea421
parent25531c71a78b98af91f25d5e6eaa362e5fc54a86 (diff)
downloadgitea-ee9ce0cfa9c003b359d2d3fba9346fd0929e88f4.tar.gz
gitea-ee9ce0cfa9c003b359d2d3fba9346fd0929e88f4.zip
Fix nil reference in repo generation (#9660)
* Fix nil reference Signed-off-by: jolheiser <john.olheiser@gmail.com> * Tighten Signed-off-by: jolheiser <john.olheiser@gmail.com>
-rw-r--r--models/repo_generate.go60
1 files changed, 31 insertions, 29 deletions
diff --git a/models/repo_generate.go b/models/repo_generate.go
index 556a5fc2f7..1b0466eaa7 100644
--- a/models/repo_generate.go
+++ b/models/repo_generate.go
@@ -124,41 +124,43 @@ func generateRepoCommit(e Engine, repo, templateRepo, generateRepo *Repository,
return fmt.Errorf("checkGiteaTemplate: %v", err)
}
- if err := os.Remove(gt.Path); err != nil {
- return fmt.Errorf("remove .giteatemplate: %v", err)
- }
-
- // Avoid walking tree if there are no globs
- if len(gt.Globs()) > 0 {
- tmpDirSlash := strings.TrimSuffix(filepath.ToSlash(tmpDir), "/") + "/"
- if err := filepath.Walk(tmpDirSlash, func(path string, info os.FileInfo, walkErr error) error {
- if walkErr != nil {
- return walkErr
- }
+ if gt != nil {
+ if err := os.Remove(gt.Path); err != nil {
+ return fmt.Errorf("remove .giteatemplate: %v", err)
+ }
- if info.IsDir() {
- return nil
- }
+ // Avoid walking tree if there are no globs
+ if len(gt.Globs()) > 0 {
+ tmpDirSlash := strings.TrimSuffix(filepath.ToSlash(tmpDir), "/") + "/"
+ if err := filepath.Walk(tmpDirSlash, func(path string, info os.FileInfo, walkErr error) error {
+ if walkErr != nil {
+ return walkErr
+ }
- base := strings.TrimPrefix(filepath.ToSlash(path), tmpDirSlash)
- for _, g := range gt.Globs() {
- if g.Match(base) {
- content, err := ioutil.ReadFile(path)
- if err != nil {
- return err
- }
+ if info.IsDir() {
+ return nil
+ }
- if err := ioutil.WriteFile(path,
- []byte(generateExpansion(string(content), templateRepo, generateRepo)),
- 0644); err != nil {
- return err
+ base := strings.TrimPrefix(filepath.ToSlash(path), tmpDirSlash)
+ for _, g := range gt.Globs() {
+ if g.Match(base) {
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return err
+ }
+
+ if err := ioutil.WriteFile(path,
+ []byte(generateExpansion(string(content), templateRepo, generateRepo)),
+ 0644); err != nil {
+ return err
+ }
+ break
}
- break
}
+ return nil
+ }); err != nil {
+ return err
}
- return nil
- }); err != nil {
- return err
}
}