diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-03 15:50:55 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-03 15:50:55 -0400 |
commit | 79a610592ea7c2e93ab2f91190af1782c4aa8f8d (patch) | |
tree | 94515ccd8e27fc7f01c08daea725bdd2f3dbee6a /models | |
parent | bbadbbdf685a7f6cb1924442a115aa88bb520e07 (diff) | |
download | gitea-79a610592ea7c2e93ab2f91190af1782c4aa8f8d.tar.gz gitea-79a610592ea7c2e93ab2f91190af1782c4aa8f8d.zip |
Add: rename repository
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 8 | ||||
-rw-r--r-- | models/repo.go | 22 |
2 files changed, 29 insertions, 1 deletions
diff --git a/models/access.go b/models/access.go index 42fccae055..83261575e6 100644 --- a/models/access.go +++ b/models/access.go @@ -32,6 +32,14 @@ func AddAccess(access *Access) error { return err } +// UpdateAccess updates access information. +func UpdateAccess(access *Access) error { + access.UserName = strings.ToLower(access.UserName) + access.RepoName = strings.ToLower(access.RepoName) + _, err := orm.Id(access.Id).Update(access) + return err +} + // HasAccess returns true if someone can read or write to given repository. func HasAccess(userName, repoName string, mode int) (bool, error) { return orm.Get(&Access{ diff --git a/models/repo.go b/models/repo.go index e3270b1838..11e23ecd0f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -369,14 +369,34 @@ func RepoPath(userName, repoName string) string { return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") } +// ChangeRepositoryName changes all corresponding setting from old repository name to new one. +func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) { + // Update accesses. + accesses := make([]Access, 0, 5) + err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}) + if err != nil { + return err + } + for i := range accesses { + accesses[i].RepoName = userName + "/" + newRepoName + if err = UpdateAccess(&accesses[i]); err != nil { + return err + } + } + + // Change repository directory name. + return os.Rename(RepoPath(userName, oldRepoName), RepoPath(userName, newRepoName)) +} + func UpdateRepository(repo *Repository) error { + repo.LowerName = strings.ToLower(repo.Name) + if len(repo.Description) > 255 { repo.Description = repo.Description[:255] } if len(repo.Website) > 255 { repo.Website = repo.Website[:255] } - _, err := orm.Id(repo.Id).AllCols().Update(repo) return err } |