From d0af61a04acba41001d7ebe426fdde3400543f1c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 22 Dec 2012 13:50:55 -0800 Subject: [PATCH] Fix bugs in enumerate handler and s3's MaxEnumerateConfig. Change-Id: Ib9cd52fe7d015a8c70416ec67ff6fd99a7a03d24 --- pkg/blobserver/handlers/enumerate.go | 2 +- pkg/blobserver/interface.go | 11 +++++++++++ pkg/blobserver/s3/enumerate.go | 5 ++++- pkg/serverconfig/serverconfig.go | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/blobserver/handlers/enumerate.go b/pkg/blobserver/handlers/enumerate.go index 42b44aee1..9faa6409a 100644 --- a/pkg/blobserver/handlers/enumerate.go +++ b/pkg/blobserver/handlers/enumerate.go @@ -56,7 +56,7 @@ func handleEnumerateBlobs(conn http.ResponseWriter, req *http.Request, storage b formValueAfter := req.FormValue("after") maxEnumerate := defaultMaxEnumerate - if config, ok := storage.(blobserver.MaxEnumerateConfig); ok { + if config, ok := blobserver.Unwrap(storage).(blobserver.MaxEnumerateConfig); ok { maxEnumerate = config.MaxEnumerate() - 1 // Since we'll add one below. } diff --git a/pkg/blobserver/interface.go b/pkg/blobserver/interface.go index 921b02ccc..95b3a250a 100644 --- a/pkg/blobserver/interface.go +++ b/pkg/blobserver/interface.go @@ -204,3 +204,14 @@ func MaybeWrapContext(sto Storage, req *http.Request) Storage { } return w.WrapContext(req) } + +// Unwrap returns the wrapped Storage interface, if wrapped, else returns sto. +func Unwrap(sto interface{}) interface{} { + type get interface { + GetStorage() Storage + } + if g, ok := sto.(get); ok { + return Unwrap(g.GetStorage()) + } + return sto +} \ No newline at end of file diff --git a/pkg/blobserver/s3/enumerate.go b/pkg/blobserver/s3/enumerate.go index d91541913..716fd9e62 100644 --- a/pkg/blobserver/s3/enumerate.go +++ b/pkg/blobserver/s3/enumerate.go @@ -21,11 +21,14 @@ import ( "time" "camlistore.org/pkg/blobref" + "camlistore.org/pkg/blobserver" ) var _ = log.Printf -func (sto *s3Storage) MaxEnumerate() uint { return 1000 } +var _ blobserver.MaxEnumerateConfig = (*s3Storage)(nil) + +func (sto *s3Storage) MaxEnumerate() int { return 1000 } func (sto *s3Storage) EnumerateBlobs(dest chan<- blobref.SizedBlobRef, after string, limit int, wait time.Duration) error { defer close(dest) diff --git a/pkg/serverconfig/serverconfig.go b/pkg/serverconfig/serverconfig.go index c9128a754..594079601 100644 --- a/pkg/serverconfig/serverconfig.go +++ b/pkg/serverconfig/serverconfig.go @@ -100,6 +100,12 @@ func (s *storageAndConfig) Config() *blobserver.Config { return s.config } +// GetStorage returns the unwrapped blobserver.Storage interface value for +// callers to type-assert optional interface implementations on. (e.g. EnumeratorConfig) +func (s *storageAndConfig) GetStorage() blobserver.Storage { + return s.Storage +} + func handleCamliUsingStorage(conn http.ResponseWriter, req *http.Request, action string, storage blobserver.StorageConfiger) { handler := unsupportedHandler switch req.Method {