Skip to content

Commit

Permalink
Merge "blobserver, all: add contexts to ReceiveBlob, Fetch & million …
Browse files Browse the repository at this point in the history
…resulting deps"
  • Loading branch information
bradfitz authored and Gerrit Code Review committed Jan 19, 2018
2 parents f1ccccb + 194d4f9 commit 1d3ab02
Show file tree
Hide file tree
Showing 165 changed files with 1,224 additions and 1,054 deletions.
3 changes: 2 additions & 1 deletion app/hello/main.go
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package main // import "perkeep.org/app/hello"

import (
"context"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -51,7 +52,7 @@ func appConfig() *config {
log.Fatalf("could not get a client to fetch extra config: %v", err)
}
conf := &config{}
if err := cl.GetJSON(configURL, conf); err != nil {
if err := cl.GetJSON(context.TODO(), configURL, conf); err != nil {
log.Fatalf("could not get app config at %v: %v", configURL, err)
}
return conf
Expand Down
14 changes: 7 additions & 7 deletions app/publisher/main.go
Expand Up @@ -103,7 +103,7 @@ func appConfig() (*config, error) {
pause := time.Second
giveupTime := time.Now().Add(time.Hour)
for {
err := cl.GetJSON(configURL, conf)
err := cl.GetJSON(context.TODO(), configURL, conf)
if err == nil {
break
}
Expand Down Expand Up @@ -436,8 +436,8 @@ func goTemplate(files *fileembed.Files, templateFile string) (*template.Template
// a *client.Client, so we can use a fake client in tests.
type client interface {
search.QueryDescriber
GetJSON(url string, data interface{}) error
Post(url string, bodyType string, body io.Reader) error
GetJSON(ctx context.Context, url string, data interface{}) error
Post(ctx context.Context, url string, bodyType string, body io.Reader) error
blob.Fetcher
}

Expand Down Expand Up @@ -520,7 +520,7 @@ func (ph *publishHandler) initRootNode() error {
func (ph *publishHandler) camliRootQuery() (*search.SearchResult, error) {
// TODO(mpl): I've voluntarily omitted the owner because it's not clear to
// me that we actually care about that. Same for signer in lookupPathTarget.
return ph.cl.Query(&search.SearchQuery{
return ph.cl.Query(context.TODO(), &search.SearchQuery{
Limit: 1,
Constraint: &search.Constraint{
Permanode: &search.PermanodeConstraint{
Expand All @@ -536,7 +536,7 @@ func (ph *publishHandler) lookupPathTarget(root blob.Ref, suffix string) (blob.R
return root, nil
}
// TODO: verify it's optimized: http://perkeep.org/issue/405
result, err := ph.cl.Query(&search.SearchQuery{
result, err := ph.cl.Query(context.TODO(), &search.SearchQuery{
Limit: 1,
Constraint: &search.Constraint{
Permanode: &search.PermanodeConstraint{
Expand Down Expand Up @@ -624,7 +624,7 @@ func (ph *publishHandler) describe(br blob.Ref) (*search.DescribedBlob, error) {
}

func (ph *publishHandler) deepDescribe(br blob.Ref) (*search.DescribeResponse, error) {
res, err := ph.cl.Query(&search.SearchQuery{
res, err := ph.cl.Query(context.TODO(), &search.SearchQuery{
Constraint: &search.Constraint{
BlobRefPrefix: br.String(),
CamliType: "permanode",
Expand Down Expand Up @@ -1166,7 +1166,7 @@ func (pr *publishRequest) subjectMembers(resMap map[string]*search.DescribedBlob
}

func (ph *publishHandler) describeMembers(br blob.Ref) (*search.SearchResult, error) {
res, err := ph.cl.Query(&search.SearchQuery{
res, err := ph.cl.Query(context.TODO(), &search.SearchQuery{
Constraint: &search.Constraint{
Permanode: &search.PermanodeConstraint{
Relation: &search.RelationConstraint{
Expand Down
9 changes: 5 additions & 4 deletions app/publisher/zip.go
Expand Up @@ -18,6 +18,7 @@ package main

import (
"archive/zip"
"context"
"crypto/sha1"
"fmt"
"io"
Expand Down Expand Up @@ -60,7 +61,7 @@ func (s sortedFiles) Len() int { return len(s) }
func (s sortedFiles) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func (zh *zipHandler) describeMembers(br blob.Ref) (*search.DescribeResponse, error) {
res, err := zh.cl.Query(&search.SearchQuery{
res, err := zh.cl.Query(context.TODO(), &search.SearchQuery{
Constraint: &search.Constraint{
BlobRefPrefix: br.String(),
CamliType: "permanode",
Expand Down Expand Up @@ -157,11 +158,11 @@ func (zh *zipHandler) blobList(dirPath string, dirBlob blob.Ref) ([]*blobFile, e
// It only traverses permanode directories.
func (zh *zipHandler) blobsFromDir(dirPath string, dirBlob blob.Ref) ([]*blobFile, error) {
var list []*blobFile
dr, err := schema.NewDirReader(zh.fetcher, dirBlob)
dr, err := schema.NewDirReader(context.TODO(), zh.fetcher, dirBlob)
if err != nil {
return nil, fmt.Errorf("Could not read dir blob %v: %v", dirBlob, err)
}
ent, err := dr.Readdir(-1)
ent, err := dr.Readdir(context.TODO(), -1)
if err != nil {
return nil, fmt.Errorf("Could not read dir entries: %v", err)
}
Expand Down Expand Up @@ -259,7 +260,7 @@ func (zh *zipHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
h.Set("Etag", fmt.Sprintf(`"%x"`, etag.Sum(nil)))

for _, file := range blobFiles {
fr, err := schema.NewFileReader(zh.fetcher, file.blobRef)
fr, err := schema.NewFileReader(context.TODO(), zh.fetcher, file.blobRef)
if err != nil {
log.Printf("Can not add %v in zip, not a file: %v", file.blobRef, err)
http.Error(rw, "Server error", http.StatusInternalServerError)
Expand Down

0 comments on commit 1d3ab02

Please sign in to comment.