aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2018-01-28 05:24:59 -0700
committerLauris BH <lauris@nix.lv>2018-01-28 14:24:59 +0200
commitbac6ac033aee695b70971293d972c47efe425b3e (patch)
tree8ba06676323cb76bb47aaf63993a8dbb3474ea00 /models/repo.go
parentc55a027da3fd71359bc6b622652a22fdeb280a80 (diff)
downloadgitea-bac6ac033aee695b70971293d972c47efe425b3e.tar.gz
gitea-bac6ac033aee695b70971293d972c47efe425b3e.zip
Fix race condition in repo renaming (#3418)
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index 4214198567..ba5b7b36af 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1579,7 +1579,12 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
return fmt.Errorf("GetRepositoryByName: %v", err)
}
- // Change repository directory name.
+ // Change repository directory name. We must lock the local copy of the
+ // repo so that we can atomically rename the repo path and updates the
+ // local copy's origin accordingly.
+ repoWorkingPool.CheckIn(com.ToStr(repo.ID))
+ defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
+
newRepoPath := RepoPath(u.Name, newRepoName)
if err = os.Rename(repo.RepoPath(), newRepoPath); err != nil {
return fmt.Errorf("rename repository directory: %v", err)