浏览代码

#1032: legacy code can have duplicated IDs for same repository

Unknwon 10 年之前
父节点
当前提交
6b70a0c0d9
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      models/migrations/migrations.go

+ 4 - 1
models/migrations/migrations.go

@@ -341,12 +341,15 @@ func teamToTeamRepo(x *xorm.Engine) error {
 		orgID := com.StrTo(team["org_id"]).MustInt64()
 		orgID := com.StrTo(team["org_id"]).MustInt64()
 		teamID := com.StrTo(team["id"]).MustInt64()
 		teamID := com.StrTo(team["id"]).MustInt64()
 
 
+		// #1032: legacy code can have duplicated IDs for same repository.
+		mark := make(map[int64]bool)
 		for _, idStr := range strings.Split(string(team["repo_ids"]), "|") {
 		for _, idStr := range strings.Split(string(team["repo_ids"]), "|") {
 			repoID := com.StrTo(strings.TrimPrefix(idStr, "$")).MustInt64()
 			repoID := com.StrTo(strings.TrimPrefix(idStr, "$")).MustInt64()
-			if repoID == 0 {
+			if repoID == 0 || mark[repoID] {
 				continue
 				continue
 			}
 			}
 
 
+			mark[repoID] = true
 			teamRepos = append(teamRepos, &TeamRepo{
 			teamRepos = append(teamRepos, &TeamRepo{
 				OrgID:  orgID,
 				OrgID:  orgID,
 				TeamID: teamID,
 				TeamID: teamID,