Skip to content

Commit bac6ac0

Browse files
ethantkoeniglafriks
authored andcommitted
Fix race condition in repo renaming (#3418)
1 parent c55a027 commit bac6ac0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

models/repo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,12 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
15791579
return fmt.Errorf("GetRepositoryByName: %v", err)
15801580
}
15811581

1582-
// Change repository directory name.
1582+
// Change repository directory name. We must lock the local copy of the
1583+
// repo so that we can atomically rename the repo path and updates the
1584+
// local copy's origin accordingly.
1585+
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
1586+
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
1587+
15831588
newRepoPath := RepoPath(u.Name, newRepoName)
15841589
if err = os.Rename(repo.RepoPath(), newRepoPath); err != nil {
15851590
return fmt.Errorf("rename repository directory: %v", err)

0 commit comments

Comments
 (0)