About this commit:

1. server/builds.go:92 used SetStatus(). Replaced with SetBuildStatus().
2. Added a index check in SetBuildTask() and return an error in case the tasks number is > than build.tasks size.
This commit is contained in:
Daniel Oliveira 2015-04-23 13:39:36 -06:00
parent 4edf385d1c
commit 987e85f261
3 changed files with 4 additions and 10 deletions

View file

@ -3,11 +3,10 @@ package bolt
import ( import (
//"bytes" //"bytes"
"encoding/binary" "encoding/binary"
"strconv"
"time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"strconv"
"time"
) )
// Build gets the specified build number for the // Build gets the specified build number for the
@ -203,12 +202,13 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
if err != nil { if err != nil {
return err return err
} }
// check index to prevent nil pointer / panic
if task.Number > len(build_.Tasks) { if task.Number > len(build_.Tasks) {
return ErrKeyNotFound return ErrKeyNotFound
} }
build_.Updated = time.Now().UTC().Unix() build_.Updated = time.Now().UTC().Unix()
//assuming task number is 1-based. //assuming task number is 1-based.
build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic build_.Tasks[task.Number-1] = task
return update(t, bucketBuild, key, build_) return update(t, bucketBuild, key, build_)
}) })
} }

View file

@ -107,10 +107,6 @@ func TestBuild(t *testing.T) {
db.SetBuild(repo, &common.Build{State: "success"}) db.SetBuild(repo, &common.Build{State: "success"})
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1}) err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
g.Assert(err_).Equal(nil) g.Assert(err_).Equal(nil)
//err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 2})
//g.Assert(err_).Equal(nil)
//err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1})
//g.Assert(err_).Equal(nil)
}) })
}) })
} }

View file

@ -89,8 +89,6 @@ func PostBuildStatus(c *gin.Context) {
c.AbortWithStatus(400) c.AbortWithStatus(400)
return return
} }
//if err := store.SetStatus(repo.Name, num, in); err != nil {
if err := store.SetBuildStatus(repo.Name, num, in); err != nil { if err := store.SetBuildStatus(repo.Name, num, in); err != nil {
c.Fail(400, err) c.Fail(400, err)
} else { } else {