2015-05-01 04:08:42 +00:00
|
|
|
package builtin
|
2015-04-07 08:20:55 +00:00
|
|
|
|
|
|
|
import (
|
2015-04-13 06:08:55 +00:00
|
|
|
"bytes"
|
2015-04-21 00:39:32 +00:00
|
|
|
"github.com/boltdb/bolt"
|
2015-04-13 06:08:55 +00:00
|
|
|
"io"
|
2015-04-07 08:20:55 +00:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2015-04-15 05:04:38 +00:00
|
|
|
// SetLogs inserts or updates a task logs for the
|
2015-04-07 08:20:55 +00:00
|
|
|
// named repository and build number.
|
2015-04-15 05:04:38 +00:00
|
|
|
func (db *DB) SetLogs(repo string, build int, task int, log []byte) error {
|
2015-04-07 08:20:55 +00:00
|
|
|
key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task))
|
|
|
|
t, err := db.Begin(true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = t.Bucket(bucketBuildLogs).Put(key, log)
|
|
|
|
if err != nil {
|
|
|
|
t.Rollback()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return t.Commit()
|
|
|
|
}
|
2015-04-15 05:04:38 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|