#1120 #1132 mirror info not updated when transfer mirro repo

This commit is contained in:
Unknwon 2015-03-25 17:50:18 -04:00
parent c5c5aac7a5
commit ab730a91f0
1 changed files with 25 additions and 4 deletions

View File

@ -283,9 +283,9 @@ type Mirror struct {
NextUpdate time.Time
}
func GetMirror(repoId int64) (*Mirror, error) {
func getMirror(e Engine, repoId int64) (*Mirror, error) {
m := &Mirror{RepoId: repoId}
has, err := x.Get(m)
has, err := e.Get(m)
if err != nil {
return nil, err
} else if !has {
@ -294,11 +294,20 @@ func GetMirror(repoId int64) (*Mirror, error) {
return m, nil
}
func UpdateMirror(m *Mirror) error {
_, err := x.Id(m.Id).Update(m)
// GetMirror returns mirror object by given repository ID.
func GetMirror(repoId int64) (*Mirror, error) {
return getMirror(x, repoId)
}
func updateMirror(e Engine, m *Mirror) error {
_, err := e.Id(m.Id).Update(m)
return err
}
func UpdateMirror(m *Mirror) error {
return updateMirror(x, m)
}
// MirrorRepository creates a mirror repository from source.
func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) error {
_, stderr, err := process.ExecTimeout(10*time.Minute,
@ -697,6 +706,18 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
return fmt.Errorf("transferRepoAction: %v", err)
}
// Update mirror information.
if repo.IsMirror {
mirror, err := getMirror(sess, repo.Id)
if err != nil {
return fmt.Errorf("getMirror: %v", err)
}
mirror.RepoName = newOwner.LowerName + "/" + repo.LowerName
if err = updateMirror(sess, mirror); err != nil {
return fmt.Errorf("updateMirror: %v", err)
}
}
// Change repository directory name.
if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
return fmt.Errorf("rename directory: %v", err)