From d75013a0e88a1f46fd16f5ba9344ff17ed84cd37 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 30 Nov 2014 02:26:29 -0500 Subject: fix #580 --- models/repo.go | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'models/repo.go') 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 + }) +} + // __ __ __ .__ // / \ / \_____ _/ |_ ____ | |__ // \ \/\/ /\__ \\ __\/ ___\| | \ -- cgit v1.2.3