diff options
author | 6543 <6543@obermui.de> | 2021-01-18 21:00:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 21:00:50 +0100 |
commit | 2686e6bbbe0e2cbb58292732b740a6944ce09c8a (patch) | |
tree | bd7aa1b2cad2184676b7d31ab018b41c6a971559 /models | |
parent | 127907c5e66d671b139a8d2bd8912911c7e58347 (diff) | |
download | gitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.tar.gz gitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.zip |
Check if label template exist first (#14384)
* add check
* refactor
* rollback repo on error after session closed
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_label.go | 10 | ||||
-rw-r--r-- | models/repo.go | 30 |
2 files changed, 17 insertions, 23 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index ea12b42ae6..54b286fe7e 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -47,7 +47,7 @@ type Label struct { func GetLabelTemplateFile(name string) ([][3]string, error) { data, err := GetRepoInitFile("label", name) if err != nil { - return nil, fmt.Errorf("GetRepoInitFile: %v", err) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)} } lines := strings.Split(string(data), "\n") @@ -62,7 +62,7 @@ func GetLabelTemplateFile(name string) ([][3]string, error) { fields := strings.SplitN(parts[0], " ", 2) if len(fields) != 2 { - return nil, fmt.Errorf("line is malformed: %s", line) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("line is malformed: %s", line)} } color := strings.Trim(fields[0], " ") @@ -70,7 +70,7 @@ func GetLabelTemplateFile(name string) ([][3]string, error) { color = "#" + color } if !LabelColorPattern.MatchString(color) { - return nil, fmt.Errorf("bad HTML color code in line: %s", line) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("bad HTML color code in line: %s", line)} } var description string @@ -167,7 +167,7 @@ func (label *Label) ForegroundColor() template.CSS { func loadLabels(labelTemplate string) ([]string, error) { list, err := GetLabelTemplateFile(labelTemplate) if err != nil { - return nil, ErrIssueLabelTemplateLoad{labelTemplate, err} + return nil, err } labels := make([]string, len(list)) @@ -186,7 +186,7 @@ func LoadLabelsFormatted(labelTemplate string) (string, error) { func initializeLabels(e Engine, id int64, labelTemplate string, isOrg bool) error { list, err := GetLabelTemplateFile(labelTemplate) if err != nil { - return ErrIssueLabelTemplateLoad{labelTemplate, err} + return err } labels := make([]*Label, len(list)) diff --git a/models/repo.go b/models/repo.go index f2453cc5c7..b11671e1fc 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1511,26 +1511,27 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [ } // DeleteRepository deletes a repository for a user or organization. +// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock) func DeleteRepository(doer *User, uid, repoID int64) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + // In case is a organization. - org, err := GetUserByID(uid) + org, err := getUserByID(sess, uid) if err != nil { return err } if org.IsOrganization() { - if err = org.GetTeams(&SearchTeamOptions{}); err != nil { + if err = org.getTeams(sess); err != nil { return err } } - sess := x.NewSession() - defer sess.Close() - if err = sess.Begin(); err != nil { - return err - } - - repo := &Repository{ID: repoID, OwnerID: uid} - has, err := sess.Get(repo) + repo := &Repository{OwnerID: uid} + has, err := sess.ID(repoID).Get(repo) if err != nil { return err } else if !has { @@ -1679,14 +1680,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error { } if err = sess.Commit(); err != nil { - sess.Close() - if len(deployKeys) > 0 { - // We need to rewrite the public keys because the commit failed - if err2 := RewriteAllPublicKeys(); err2 != nil { - return fmt.Errorf("Commit: %v SSH Keys: %v", err, err2) - } - } - return fmt.Errorf("Commit: %v", err) + return err } sess.Close() |