summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-18 15:37:48 -0500
committerUnknwon <u@gogs.io>2015-11-18 15:37:48 -0500
commitefea642d6cf419c9587d44b95ff2bc04e89f7bfe (patch)
tree56e466a92cd206609a74b9c07db436127af2abe5 /models
parent81d7359fdd3042aed0bcb4a8e5dee24208d34e58 (diff)
downloadgitea-efea642d6cf419c9587d44b95ff2bc04e89f7bfe.tar.gz
gitea-efea642d6cf419c9587d44b95ff2bc04e89f7bfe.zip
add admin op: delete missing repos
Diffstat (limited to 'models')
-rw-r--r--models/repo.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go
index 174fbd9d59..1521f1e063 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1325,6 +1325,42 @@ func DeleteRepositoryArchives() error {
})
}
+// DeleteMissingRepositories deletes all repository records that lost Git files.
+func DeleteMissingRepositories() error {
+ repos := make([]*Repository, 0, 5)
+ if err := x.Where("id > 0").Iterate(new(Repository),
+ func(idx int, bean interface{}) error {
+ repo := bean.(*Repository)
+ repoPath, err := repo.RepoPath()
+ if err != nil {
+ return fmt.Errorf("RepoPath [%d]: %v", repo.ID, err)
+ }
+
+ if !com.IsDir(repoPath) {
+ repos = append(repos, repo)
+ }
+ return nil
+ }); err != nil {
+ if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteMissingRepositories: %v", err)); err2 != nil {
+ log.Error(4, "CreateRepositoryNotice: %v", err2)
+ }
+ return nil
+ }
+
+ if len(repos) == 0 {
+ return nil
+ }
+
+ for _, repo := range repos {
+ if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil {
+ if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
+ log.Error(4, "CreateRepositoryNotice: %v", err2)
+ }
+ }
+ }
+ return nil
+}
+
// RewriteRepositoryUpdateHook rewrites all repositories' update hook.
func RewriteRepositoryUpdateHook() error {
return x.Where("id > 0").Iterate(new(Repository),