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"
|
|
|
|
"io"
|
2015-05-08 05:31:25 +00:00
|
|
|
"io/ioutil"
|
2015-04-07 08:20:55 +00:00
|
|
|
"strconv"
|
2015-05-08 05:31:25 +00:00
|
|
|
|
|
|
|
"github.com/boltdb/bolt"
|
2015-04-07 08:20:55 +00:00
|
|
|
)
|
|
|
|
|
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-05-08 05:31:25 +00:00
|
|
|
func (db *DB) SetLogs(repo string, build int, task int, rd io.Reader) 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
|
|
|
|
}
|
2015-05-08 05:31:25 +00:00
|
|
|
|
|
|
|
log, err := ioutil.ReadAll(rd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-04-07 08:20:55 +00:00
|
|
|
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
|
|
|
|
}
|