Merge branch 'fix-list-blobs' of https://github.com/joodie/jclouds

* 'fix-list-blobs' of https://github.com/joodie/jclouds:
  make prefix optional for blobstore/list-blobs
  make blobstore/list-blobs actually lazy
This commit is contained in:
Adrian Cole 2011-03-31 10:03:52 -07:00
commit c352895ae2
1 changed files with 14 additions and 3 deletions

View File

@ -148,8 +148,10 @@ Options can also be specified for extension modules
(defn- list-blobs-chunk [container prefix #^BlobStore blobstore & [marker]] (defn- list-blobs-chunk [container prefix #^BlobStore blobstore & [marker]]
(apply list-container blobstore container (apply list-container blobstore container
:in-directory prefix (when (string? marker) (concat (when prefix
[:after-marker marker]))) [:in-directory prefix])
(when (string? marker)
[:after-marker marker]))))
(defn- list-blobs-chunks [container prefix #^BlobStore blobstore marker] (defn- list-blobs-chunks [container prefix #^BlobStore blobstore marker]
(when marker (when marker
@ -158,10 +160,19 @@ Options can also be specified for extension modules
(list-blobs-chunks container prefix blobstore (list-blobs-chunks container prefix blobstore
(.getNextMarker chunk))))))) (.getNextMarker chunk)))))))
(defn- concat-elements
"Make a lazy concatenation of the lazy sequences contained in coll. Lazily evaluates coll.
Note: (apply concat coll) or (lazy-cat coll) are not lazy wrt coll itself."
[coll]
(if-let [s (seq coll)]
(lazy-seq (concat (first s) (concat-elements (next s))))))
(defn list-blobs (defn list-blobs
"Returns a lazy seq of all blobs in the given container." "Returns a lazy seq of all blobs in the given container."
([container prefix #^BlobStore blobstore] ([container prefix #^BlobStore blobstore]
(apply concat (list-blobs-chunks container prefix blobstore :start)))) (concat-elements (list-blobs-chunks container prefix blobstore :start)))
([container #^BlobStore blobstore]
(list-blobs container nil blobstore)))
(defn locations (defn locations
"Retrieve the available container locations for the blobstore context." "Retrieve the available container locations for the blobstore context."