From 3111bd5e0e92da29d8738039d97bcb5e92e6fe48 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 15 Jun 2013 18:04:34 -0700 Subject: [PATCH] encrypt: enumerate support Change-Id: Ia7a20b2501a53b52fb514763c57e0ed2d6468735 --- pkg/blobserver/encrypt/encrypt.go | 45 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/pkg/blobserver/encrypt/encrypt.go b/pkg/blobserver/encrypt/encrypt.go index 988a0c990..4b12cd3ff 100644 --- a/pkg/blobserver/encrypt/encrypt.go +++ b/pkg/blobserver/encrypt/encrypt.go @@ -120,15 +120,14 @@ func (s *storage) StatBlobs(dest chan<- blobref.SizedBlobRef, blobs []*blobref.B if err != nil { return err } - slash := strings.Index(v, "/") - if slash < 0 { + plainSize, ok := parseMetaValuePlainSize(v) + if !ok { continue } - plainSize, err := strconv.Atoi(v[:slash]) if err != nil { continue } - dest <- blobref.SizedBlobRef{br, int64(plainSize)} + dest <- blobref.SizedBlobRef{br, plainSize} } return nil } @@ -198,7 +197,31 @@ func (s *storage) FetchStreaming(b *blobref.BlobRef) (file io.ReadCloser, size i } func (s *storage) EnumerateBlobs(dest chan<- blobref.SizedBlobRef, after string, limit int, wait time.Duration) error { - panic("TODO: implement") + if wait != 0 { + panic("TODO: support wait in EnumerateBlobs") + } + defer close(dest) + iter := s.index.Find(after) + n := 0 + for iter.Next() { + if iter.Key() == after { + continue + } + br := blobref.Parse(iter.Key()) + if br == nil { + panic("Bogus encrypt index key: " + iter.Key()) + } + plainSize, ok := parseMetaValuePlainSize(iter.Value()) + if !ok { + panic("Bogus encrypt index value: " + iter.Value()) + } + dest <- blobref.SizedBlobRef{br, plainSize} + n++ + if limit != 0 && n >= limit { + break + } + } + return iter.Close() } func encodeMetaValue(plainSize int64, iv []byte, encBR *blobref.BlobRef, encSize int) string { @@ -224,6 +247,18 @@ func (s *storage) fetchMeta(b *blobref.BlobRef) (*metaValue, error) { return parseMetaValue(v) } +func parseMetaValuePlainSize(v string) (plainSize int64, ok bool) { + slash := strings.Index(v, "/") + if slash < 0 { + return + } + n, err := strconv.Atoi(v[:slash]) + if err != nil { + return + } + return int64(n), true +} + func parseMetaValue(v string) (mv *metaValue, err error) { f := strings.Split(v, "/") if len(f) != 4 {