woodpecker/datastore/builtin/task.go
Daniel Oliveira ba159976a0 Fixing TODO comments in code /cc @oliveiradan
1. server/login.go:49 (// TODO(bradrydzewski) return an error message instead). Added error message if authorization fails.
2. server/repos.go:178 (TODO(bradrydzewski) verify repo not exists). Added a checking for the repo and return an error in case it does not exist.
3. server/queue.go:170:  // TODO (bradrydzewski) change this interface to accept an io.Reader. All references to the API change been in question SetLogs() have been modified.
4. remote/github/github.go:106  // Fixed a crash in case *repo_.Language is nil , when de-referencing it. This could happen when a repo only has a readme, so github hasn't set the language yet.
5. ./server/queue.go:170:  // TODO (bradrydzewski) change this interface to accept an io.Reader. All references to the API change been in question SetLogs() have been modified.
6. .remote/github/github.go:106  // Fixed a crash in case *repo_.Language is nil , when de-referencing it. This could happen when a repo only has a readme, so github hasn't set the language yet.
2015-05-08 10:47:40 -06:00

47 lines
1,005 B
Go

package builtin
import (
"bytes"
"io"
"io/ioutil"
"strconv"
"github.com/boltdb/bolt"
)
// SetLogs inserts or updates a task logs for the
// named repository and build number.
func (db *DB) SetLogs(repo string, build int, task int, rd io.Reader) error {
key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task))
t, err := db.Begin(true)
if err != nil {
return err
}
log, err := ioutil.ReadAll(rd)
if err != nil {
return err
}
err = t.Bucket(bucketBuildLogs).Put(key, log)
if err != nil {
t.Rollback()
return err
}
return t.Commit()
}
// LogReader gets the task logs at index N for
// the named repository and build number.
func (db *DB) LogReader(repo string, build int, task int) (io.Reader, error) {
key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task))
var log []byte
err := db.View(func(t *bolt.Tx) error {
var err error
log, err = raw(t, bucketBuildLogs, key)
return err
})
buf := bytes.NewBuffer(log)
return buf, err
}