diff --git a/lib/go/camli/index/enumstat.go b/lib/go/camli/index/enumstat.go index c5b1c49a1..839150330 100644 --- a/lib/go/camli/index/enumstat.go +++ b/lib/go/camli/index/enumstat.go @@ -17,6 +17,7 @@ limitations under the License. package index import ( + "fmt" "os" "strconv" "strings" @@ -44,6 +45,20 @@ func (ix *Index) EnumerateBlobs(dest chan<- blobref.SizedBlobRef, after string, } func (ix *Index) StatBlobs(dest chan<- blobref.SizedBlobRef, blobs []*blobref.BlobRef, waitSeconds int) os.Error { - panic("TODO") + for _, br := range blobs { + key := "have:" + br.String() + v, err := ix.s.Get(key) + if err == ErrNotFound { + continue + } + if err != nil { + return fmt.Errorf("error looking up key %q: %v", key, err) + } + size, err := strconv.Atoi64(v) + if err != nil { + return fmt.Errorf("invalid size for key %q = %q", key, v) + } + dest <- blobref.SizedBlobRef{br, size} + } return nil } diff --git a/lib/go/camli/index/index.go b/lib/go/camli/index/index.go index d87c0015a..d0e3b6b80 100644 --- a/lib/go/camli/index/index.go +++ b/lib/go/camli/index/index.go @@ -25,7 +25,13 @@ import ( "camli/search" ) +var ErrNotFound = os.NewError("index: key not found") + type IndexStorage interface { + // Get gets the value for the given key. It returns ErrNotFound if the DB + // does not contain the key. + Get(key string) (string, os.Error) + Set(key, value string) os.Error Delete(key string) os.Error diff --git a/lib/go/camli/index/memindex.go b/lib/go/camli/index/memindex.go index 56e93cdfa..0e5c42d50 100644 --- a/lib/go/camli/index/memindex.go +++ b/lib/go/camli/index/memindex.go @@ -53,6 +53,16 @@ func (s stringIterator) Value() string { return string(s.Iterator.Value()) } +func (mk *memKeys) Get(key string) (string, os.Error) { + mk.mu.Lock() + defer mk.mu.Unlock() + k, err := mk.db.Get([]byte(key)) + if err == db.ErrNotFound { + return "", ErrNotFound + } + return string(k), err +} + func (mk *memKeys) Find(key string) Iterator { mk.mu.Lock() defer mk.mu.Unlock()