forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.go
71 lines (63 loc) · 1.86 KB
/
files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package datastore
import (
"bytes"
"io"
"io/ioutil"
"github.com/drone/drone/model"
"github.com/drone/drone/store/datastore/sql"
"github.com/russross/meddler"
)
func (db *datastore) FileList(build *model.Build) ([]*model.File, error) {
stmt := sql.Lookup(db.driver, "files-find-build")
list := []*model.File{}
err := meddler.QueryAll(db, &list, stmt, build.ID)
return list, err
}
func (db *datastore) FileFind(proc *model.Proc, name string) (*model.File, error) {
stmt := sql.Lookup(db.driver, "files-find-proc-name")
file := new(model.File)
err := meddler.QueryRow(db, file, stmt, proc.ID, name)
return file, err
}
func (db *datastore) FileRead(proc *model.Proc, name string) (io.ReadCloser, error) {
stmt := sql.Lookup(db.driver, "files-find-proc-name-data")
file := new(fileData)
err := meddler.QueryRow(db, file, stmt, proc.ID, name)
buf := bytes.NewBuffer(file.Data)
return ioutil.NopCloser(buf), err
}
func (db *datastore) FileCreate(file *model.File, r io.Reader) error {
d, err := ioutil.ReadAll(r)
if err != nil {
return err
}
f := fileData{
ID: file.ID,
BuildID: file.BuildID,
ProcID: file.ProcID,
PID: file.PID,
Name: file.Name,
Size: file.Size,
Mime: file.Mime,
Time: file.Time,
Passed: file.Passed,
Failed: file.Failed,
Skipped: file.Skipped,
Data: d,
}
return meddler.Insert(db, "files", &f)
}
type fileData struct {
ID int64 `meddler:"file_id,pk"`
BuildID int64 `meddler:"file_build_id"`
ProcID int64 `meddler:"file_proc_id"`
PID int `meddler:"file_pid"`
Name string `meddler:"file_name"`
Size int `meddler:"file_size"`
Mime string `meddler:"file_mime"`
Time int64 `meddler:"file_time"`
Passed int `meddler:"file_meta_passed"`
Failed int `meddler:"file_meta_failed"`
Skipped int `meddler:"file_meta_skipped"`
Data []byte `meddler:"file_data"`
}