浏览代码

fix #1119 and data race in timming tasks

tags/v0.9.99
Unknwon 8 年前
父节点
当前提交
3d14e73fd8
共有 3 个文件被更改,包括 75 次插入16 次删除
  1. 49
    14
      models/repo.go
  2. 23
    2
      modules/git/tree.go
  3. 3
    0
      routers/user/home.go

+ 49
- 14
models/repo.go 查看文件

"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"unicode/utf8" "unicode/utf8"


}) })
} }


var (
// Prevent duplicate running tasks.
isMirrorUpdating = false
isGitFscking = false
isCheckingRepos = false
// statusPool represents a pool of status with true/false.
type statusPool struct {
lock sync.RWMutex
pool map[string]bool
}

// Start sets value of given name to true in the pool.
func (p *statusPool) Start(name string) {
p.lock.Lock()
defer p.lock.Unlock()

p.pool[name] = true
}

// Stop sets value of given name to false in the pool.
func (p *statusPool) Stop(name string) {
p.lock.Lock()
defer p.lock.Unlock()

p.pool[name] = false
}

// IsRunning checks if value of given name is set to true in the pool.
func (p *statusPool) IsRunning(name string) bool {
p.lock.RLock()
defer p.lock.RUnlock()

return p.pool[name]
}

// Prevent duplicate running tasks.
var taskStatusPool = &statusPool{
pool: make(map[string]bool),
}

const (
_MIRROR_UPDATE = "mirror_update"
_GIT_FSCK = "git_fsck"
_CHECK_REPOs = "check_repos"
) )


// MirrorUpdate checks and updates mirror repositories. // MirrorUpdate checks and updates mirror repositories.
func MirrorUpdate() { func MirrorUpdate() {
if isMirrorUpdating {
if taskStatusPool.IsRunning(_MIRROR_UPDATE) {
return return
} }
isMirrorUpdating = true
defer func() { isMirrorUpdating = false }()
taskStatusPool.Start(_MIRROR_UPDATE)
defer taskStatusPool.Stop(_MIRROR_UPDATE)


log.Trace("Doing: MirrorUpdate") log.Trace("Doing: MirrorUpdate")




// GitFsck calls 'git fsck' to check repository health. // GitFsck calls 'git fsck' to check repository health.
func GitFsck() { func GitFsck() {
if isGitFscking {
if taskStatusPool.IsRunning(_GIT_FSCK) {
return return
} }
isGitFscking = true
defer func() { isGitFscking = false }()
taskStatusPool.Start(_GIT_FSCK)
defer taskStatusPool.Stop(_GIT_FSCK)


log.Trace("Doing: GitFsck") log.Trace("Doing: GitFsck")


} }


func CheckRepoStats() { func CheckRepoStats() {
if isCheckingRepos {
if taskStatusPool.IsRunning(_CHECK_REPOs) {
return return
} }
isCheckingRepos = true
defer func() { isCheckingRepos = false }()
taskStatusPool.Start(_CHECK_REPOs)
defer taskStatusPool.Stop(_CHECK_REPOs)


log.Trace("Doing: CheckRepoStats") log.Trace("Doing: CheckRepoStats")



+ 23
- 2
modules/git/tree.go 查看文件

entriesParsed bool entriesParsed bool
} }


var escapeChar = []byte("\\")

func unescapeChars(in []byte) []byte {
if bytes.Index(in, escapeChar) == -1 {
return in
}

endIdx := len(in) - 1
isEscape := false
out := make([]byte, 0, endIdx+1)
for i := range in {
if in[i] == '\\' && i != endIdx {
isEscape = !isEscape
if isEscape {
continue
}
}
out = append(out, in[i])
}
return out
}

// Parse tree information from the (uncompressed) raw // Parse tree information from the (uncompressed) raw
// data from the tree object. // data from the tree object.
func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) { func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {


// In case entry name is surrounded by double quotes(it happens only in git-shell). // In case entry name is surrounded by double quotes(it happens only in git-shell).
if entry.name[0] == '"' { if entry.name[0] == '"' {
entry.name = string(data[pos+1 : pos+step-1])
entry.name = strings.Replace(entry.name, `\"`, `"`, -1)
entry.name = string(unescapeChars(data[pos+1 : pos+step-1]))
} }


pos += step + 1 pos += step + 1

+ 3
- 0
routers/user/home.go 查看文件

if uname == "favicon.ico" { if uname == "favicon.ico" {
ctx.Redirect(setting.AppSubUrl + "/img/favicon.png") ctx.Redirect(setting.AppSubUrl + "/img/favicon.png")
return return
} else if strings.HasSuffix(uname, ".png") {
ctx.Error(404)
return
} }


isShowKeys := false isShowKeys := false

正在加载...
取消
保存