summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-10-30 09:20:18 +0800
committerGitHub <noreply@github.com>2018-10-30 09:20:18 +0800
commit4d66de684f845f4f4ca095a4efb096fbf6288176 (patch)
tree04c0d2292a2cb8861c0c70a29eb392a41497f8c9
parentd220a3d7724aed24d3b461dd3971261b9cb5fcd8 (diff)
downloadgitea-4d66de684f845f4f4ca095a4efb096fbf6288176.tar.gz
gitea-4d66de684f845f4f4ca095a4efb096fbf6288176.zip
Fix race on updatesize (#5190) (#5215)
* fix race on updatesize * fix more repoPath
-rw-r--r--models/repo.go4
-rw-r--r--models/status.go15
2 files changed, 10 insertions, 9 deletions
diff --git a/models/repo.go b/models/repo.go
index 25def6ad8f..b14b0c7705 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -681,7 +681,7 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
}
func (repo *Repository) updateSize(e Engine) error {
- repoInfoSize, err := git.GetRepoSize(repo.RepoPath())
+ repoInfoSize, err := git.GetRepoSize(repo.repoPath(e))
if err != nil {
return fmt.Errorf("UpdateSize: %v", err)
}
@@ -1709,7 +1709,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
}
// Create/Remove git-daemon-export-ok for git-daemon...
- daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
+ daemonExportFile := path.Join(repo.repoPath(e), `git-daemon-export-ok`)
if repo.IsPrivate && com.IsExist(daemonExportFile) {
if err = os.Remove(daemonExportFile); err != nil {
log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
diff --git a/models/status.go b/models/status.go
index 3146f8d303..91d011f7c5 100644
--- a/models/status.go
+++ b/models/status.go
@@ -197,14 +197,15 @@ func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
return fmt.Errorf("newCommitStatus[nil, %s]: no repository specified", opts.SHA)
}
opts.CommitStatus.RepoID = opts.Repo.ID
+ repoPath := opts.Repo.repoPath(sess)
if opts.Creator == nil {
- return fmt.Errorf("newCommitStatus[%s, %s]: no user specified", opts.Repo.RepoPath(), opts.SHA)
+ return fmt.Errorf("newCommitStatus[%s, %s]: no user specified", repoPath, opts.SHA)
}
- gitRepo, err := git.OpenRepository(opts.Repo.RepoPath())
+ gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
- return fmt.Errorf("OpenRepository[%s]: %v", opts.Repo.RepoPath(), err)
+ return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
}
if _, err := gitRepo.GetCommit(opts.SHA); err != nil {
return fmt.Errorf("GetCommit[%s]: %v", opts.SHA, err)
@@ -219,19 +220,19 @@ func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
has, err := sess.Desc("index").Limit(1).Get(lastCommitStatus)
if err != nil {
sess.Rollback()
- return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
+ return fmt.Errorf("newCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
}
if has {
- log.Debug("newCommitStatus[%s, %s]: found", opts.Repo.RepoPath(), opts.SHA)
+ log.Debug("newCommitStatus[%s, %s]: found", repoPath, opts.SHA)
nextIndex = lastCommitStatus.Index
}
opts.CommitStatus.Index = nextIndex + 1
- log.Debug("newCommitStatus[%s, %s]: %d", opts.Repo.RepoPath(), opts.SHA, opts.CommitStatus.Index)
+ log.Debug("newCommitStatus[%s, %s]: %d", repoPath, opts.SHA, opts.CommitStatus.Index)
// Insert new CommitStatus
if _, err = sess.Insert(opts.CommitStatus); err != nil {
sess.Rollback()
- return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
+ return fmt.Errorf("newCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
}
return nil