Skip to content

Commit 4d66de6

Browse files
authored
Fix race on updatesize (#5190) (#5215)
* fix race on updatesize * fix more repoPath
1 parent d220a3d commit 4d66de6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

models/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
681681
}
682682

683683
func (repo *Repository) updateSize(e Engine) error {
684-
repoInfoSize, err := git.GetRepoSize(repo.RepoPath())
684+
repoInfoSize, err := git.GetRepoSize(repo.repoPath(e))
685685
if err != nil {
686686
return fmt.Errorf("UpdateSize: %v", err)
687687
}
@@ -1709,7 +1709,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
17091709
}
17101710

17111711
// Create/Remove git-daemon-export-ok for git-daemon...
1712-
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
1712+
daemonExportFile := path.Join(repo.repoPath(e), `git-daemon-export-ok`)
17131713
if repo.IsPrivate && com.IsExist(daemonExportFile) {
17141714
if err = os.Remove(daemonExportFile); err != nil {
17151715
log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)

models/status.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
197197
return fmt.Errorf("newCommitStatus[nil, %s]: no repository specified", opts.SHA)
198198
}
199199
opts.CommitStatus.RepoID = opts.Repo.ID
200+
repoPath := opts.Repo.repoPath(sess)
200201

201202
if opts.Creator == nil {
202-
return fmt.Errorf("newCommitStatus[%s, %s]: no user specified", opts.Repo.RepoPath(), opts.SHA)
203+
return fmt.Errorf("newCommitStatus[%s, %s]: no user specified", repoPath, opts.SHA)
203204
}
204205

205-
gitRepo, err := git.OpenRepository(opts.Repo.RepoPath())
206+
gitRepo, err := git.OpenRepository(repoPath)
206207
if err != nil {
207-
return fmt.Errorf("OpenRepository[%s]: %v", opts.Repo.RepoPath(), err)
208+
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
208209
}
209210
if _, err := gitRepo.GetCommit(opts.SHA); err != nil {
210211
return fmt.Errorf("GetCommit[%s]: %v", opts.SHA, err)
@@ -219,19 +220,19 @@ func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
219220
has, err := sess.Desc("index").Limit(1).Get(lastCommitStatus)
220221
if err != nil {
221222
sess.Rollback()
222-
return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
223+
return fmt.Errorf("newCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
223224
}
224225
if has {
225-
log.Debug("newCommitStatus[%s, %s]: found", opts.Repo.RepoPath(), opts.SHA)
226+
log.Debug("newCommitStatus[%s, %s]: found", repoPath, opts.SHA)
226227
nextIndex = lastCommitStatus.Index
227228
}
228229
opts.CommitStatus.Index = nextIndex + 1
229-
log.Debug("newCommitStatus[%s, %s]: %d", opts.Repo.RepoPath(), opts.SHA, opts.CommitStatus.Index)
230+
log.Debug("newCommitStatus[%s, %s]: %d", repoPath, opts.SHA, opts.CommitStatus.Index)
230231

231232
// Insert new CommitStatus
232233
if _, err = sess.Insert(opts.CommitStatus); err != nil {
233234
sess.Rollback()
234-
return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
235+
return fmt.Errorf("newCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
235236
}
236237

237238
return nil

0 commit comments

Comments
 (0)