Browse Source

Add repository setting to enable/disable health checks (#3607)

New Feature:
  * Repository struct field for IsFsckEnabled (default true of course)
  * Admin Settings section on repo options page, accessible only by
    admin users

Possible Enhancements:
  * There's no way to force running health checks on all repos
    regardless of their IsFsckEnabled setting. This would be useful if
    there were an admin API or dashboard button to run fsck immediately.

Issue: https://github.com/go-gitea/gitea/issues/1712
Signed-off-by: Allen Wild <allenwild93@gmail.com>
tags/v1.5.0-dev
Allen Wild 6 years ago
parent
commit
15c6bb500b

+ 2
- 0
models/migrations/migrations.go View File

NewMigration("add label descriptions", addLabelsDescriptions), NewMigration("add label descriptions", addLabelsDescriptions),
// v59 -> v60 // v59 -> v60
NewMigration("add merge whitelist for protected branches", addProtectedBranchMergeWhitelist), NewMigration("add merge whitelist for protected branches", addProtectedBranchMergeWhitelist),
// v60 -> v61
NewMigration("add is_fsck_enabled column for repos", addFsckEnabledToRepo),
} }


// Migrate database to current version // Migrate database to current version

+ 22
- 0
models/migrations/v60.go View File

// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"github.com/go-xorm/xorm"
)

func addFsckEnabledToRepo(x *xorm.Engine) error {
type Repository struct {
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
}

if err := x.Sync2(new(Repository)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}

+ 3
- 2
models/repo.go View File

BaseRepo *Repository `xorm:"-"` BaseRepo *Repository `xorm:"-"`
Size int64 `xorm:"NOT NULL DEFAULT 0"` Size int64 `xorm:"NOT NULL DEFAULT 0"`
IndexerStatus *RepoIndexerStatus `xorm:"-"` IndexerStatus *RepoIndexerStatus `xorm:"-"`
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`


CreatedUnix util.TimeStamp `xorm:"INDEX created"` CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
log.Trace("Doing: GitFsck") log.Trace("Doing: GitFsck")


if err := x. if err := x.
Where("id>0").BufferSize(setting.IterateBufferSize).
Where("id>0 AND is_fsck_enabled=?", true).BufferSize(setting.IterateBufferSize).
Iterate(new(Repository), Iterate(new(Repository),
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
repo := bean.(*Repository) repo := bean.(*Repository)
repoPath := repo.RepoPath() repoPath := repo.RepoPath()
log.Trace(fmt.Sprintf("Running health check for repository %s", repoPath))
log.Trace("Running health check on repository %s", repoPath)
if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil { if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err) desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
log.Warn(desc) log.Warn(desc)

+ 3
- 0
modules/auth/repo_form.go View File

PullsAllowSquash bool PullsAllowSquash bool
EnableTimetracker bool EnableTimetracker bool
AllowOnlyContributorsToTrackTime bool AllowOnlyContributorsToTrackTime bool

// Admin settings
EnableHealthCheck bool
} }


// Validate validates the fields // Validate validates the fields

+ 2
- 0
options/locale/locale_en-US.ini View File

settings.pulls.allow_merge_commits = Allow merge commits settings.pulls.allow_merge_commits = Allow merge commits
settings.pulls.allow_rebase_merge = Allow rebase to merge commits settings.pulls.allow_rebase_merge = Allow rebase to merge commits
settings.pulls.allow_squash_commits = Allow to squash commits before merging settings.pulls.allow_squash_commits = Allow to squash commits before merging
settings.admin_settings = Admin Settings
settings.admin_enable_health_check = Enable health checks (git fsck) for this repo
settings.danger_zone = Danger Zone settings.danger_zone = Danger Zone
settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name. settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name.
settings.convert = Convert To Regular Repository settings.convert = Convert To Regular Repository

+ 18
- 0
routers/repo/setting.go View File

ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings") ctx.Redirect(ctx.Repo.RepoLink + "/settings")


case "admin":
if !ctx.User.IsAdmin {
ctx.Error(403)
return
}

if repo.IsFsckEnabled != form.EnableHealthCheck {
repo.IsFsckEnabled = form.EnableHealthCheck
if err := models.UpdateRepository(repo, false); err != nil {
ctx.ServerError("UpdateRepository", err)
return
}
log.Trace("Repository admin settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name)
}

ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

case "convert": case "convert":
if !ctx.Repo.IsOwner() { if !ctx.Repo.IsOwner() {
ctx.Error(404) ctx.Error(404)

+ 23
- 0
templates/repo/settings/options.tmpl View File

</form> </form>
</div> </div>


{{if .IsAdmin}}
<h4 class="ui top attached header">
{{.i18n.Tr "repo.settings.admin_settings"}}
</h4>
<div class="ui attached segment">
<form class="ui form" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="admin">
<div class="field">
<div class="ui checkbox">
<input name="enable_health_check" type="checkbox" {{if .Repository.IsFsckEnabled}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.admin_enable_health_check"}}</label>
</div>
</div>

<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{$.i18n.Tr "repo.settings.update_settings"}}</button>
</div>
</form>
</div>
{{end}}

{{if .IsRepositoryOwner}} {{if .IsRepositoryOwner}}
<h4 class="ui top attached warning header"> <h4 class="ui top attached warning header">
{{.i18n.Tr "repo.settings.danger_zone"}} {{.i18n.Tr "repo.settings.danger_zone"}}

Loading…
Cancel
Save