encrypt: enumerate support

Change-Id: Ia7a20b2501a53b52fb514763c57e0ed2d6468735
This commit is contained in:
Brad Fitzpatrick 2013-06-15 18:04:34 -07:00
parent 3b6b49cb89
commit 3111bd5e0e
1 changed files with 40 additions and 5 deletions

View File

@ -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 {