From bac6ac033aee695b70971293d972c47efe425b3e Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Sun, 28 Jan 2018 05:24:59 -0700 Subject: [PATCH] Fix race condition in repo renaming (#3418) --- models/repo.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/repo.go b/models/repo.go index 42141985673e..ba5b7b36aff5 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)