summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-30 02:26:29 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-30 02:26:29 -0500
commitd75013a0e88a1f46fd16f5ba9344ff17ed84cd37 (patch)
treec153e256f1608c219e4717e3fab217c8aec1187b /models
parentb6437b5a4c52bceb8032b00b474c2aa0ced69575 (diff)
downloadgitea-d75013a0e88a1f46fd16f5ba9344ff17ed84cd37.tar.gz
gitea-d75013a0e88a1f46fd16f5ba9344ff17ed84cd37.zip
fix #580
Diffstat (limited to 'models')
-rw-r--r--models/repo.go51
-rw-r--r--models/user.go1
2 files changed, 41 insertions, 11 deletions
diff --git a/models/repo.go b/models/repo.go
index e4f470680f..5676a443ff 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1140,18 +1140,8 @@ type SearchOption struct {
Private bool
}
-// FilterSQLInject tries to prevent SQL injection.
-func FilterSQLInject(key string) string {
- key = strings.TrimSpace(key)
- key = strings.Split(key, " ")[0]
- key = strings.Replace(key, ",", "", -1)
- return key
-}
-
// SearchRepositoryByName returns given number of repositories whose name contains keyword.
func SearchRepositoryByName(opt SearchOption) (repos []*Repository, err error) {
- // Prevent SQL inject.
- opt.Keyword = FilterSQLInject(opt.Keyword)
if len(opt.Keyword) == 0 {
return repos, nil
}
@@ -1183,6 +1173,47 @@ func DeleteRepositoryArchives() error {
})
}
+// GitFsck calls 'git fsck' to check repository health.
+func GitFsck() {
+ args := append([]string{"fsck"}, setting.GitFsckArgs...)
+ if err := x.Where("id > 0").Iterate(new(Repository),
+ func(idx int, bean interface{}) error {
+ repo := bean.(*Repository)
+ if err := repo.GetOwner(); err != nil {
+ return err
+ }
+
+ repoPath := RepoPath(repo.Owner.Name, repo.Name)
+ _, _, err := process.ExecDir(-1, repoPath, "Repository health check", "git", args...)
+ if err != nil {
+ desc := fmt.Sprintf("Fail to health check repository(%s)", repoPath)
+ log.Warn(desc)
+ if err = CreateRepositoryNotice(desc); err != nil {
+ log.Error(4, "Fail to add notice: %v", err)
+ }
+ }
+ return nil
+ }); err != nil {
+ log.Error(4, "repo.Fsck: %v", err)
+ }
+}
+
+func GitGcRepos() error {
+ args := append([]string{"gc"}, setting.GitGcArgs...)
+ return x.Where("id > 0").Iterate(new(Repository),
+ func(idx int, bean interface{}) error {
+ repo := bean.(*Repository)
+ if err := repo.GetOwner(); err != nil {
+ return err
+ }
+ _, stderr, err := process.ExecDir(-1, RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection", "git", args...)
+ if err != nil {
+ return fmt.Errorf("%v: %v", err, stderr)
+ }
+ return nil
+ })
+}
+
// __ __ __ .__
// / \ / \_____ _/ |_ ____ | |__
// \ \/\/ /\__ \\ __\/ ___\| | \
diff --git a/models/user.go b/models/user.go
index 9eead462e2..61a43ba9bf 100644
--- a/models/user.go
+++ b/models/user.go
@@ -628,7 +628,6 @@ func GetUserByEmail(email string) (*User, error) {
// SearchUserByName returns given number of users whose name contains keyword.
func SearchUserByName(opt SearchOption) (us []*User, err error) {
- opt.Keyword = FilterSQLInject(opt.Keyword)
if len(opt.Keyword) == 0 {
return us, nil
}