]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add backend support for listing container contents. refs #1759
authorDaira Hopwood <daira@jacaranda.org>
Tue, 8 Apr 2014 21:43:24 +0000 (22:43 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 16 Oct 2015 16:58:54 +0000 (17:58 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/interfaces.py
src/allmydata/storage/backends/cloud/cloud_backend.py
src/allmydata/storage/backends/disk/disk_backend.py
src/allmydata/storage/backends/null/null_backend.py

index 2d103bf2b7dd330acc7b6bd903707e46fe0a3485..fb04775c0b9a6d00b31a9f93a68e06c64f110259 100644 (file)
@@ -366,6 +366,13 @@ class IStorageBackend(Interface):
         created. It is an error to attempt to create a container that already exists.
         """
 
+    def list_container(prefix=str):
+        """
+        Return a Deferred that fires with a list of ContainerItems for all
+        objects in the backend container. If prefix is given, restrict the
+        list to objects having keys with the given prefix.
+        """
+
 
 class IShareSet(Interface):
     def get_storage_index():
index dbf9146122e3b868a70cf6aae318298ee86224c7..217864f7c5f3af106d3d19346d03b553084cfcfb 100644 (file)
@@ -100,6 +100,11 @@ class CloudBackend(Backend):
     def create_container(self):
         return self._container.create()
 
+    def list_container(self, prefix=''):
+        d = self._container.list_objects(prefix)
+        d.addCallback(lambda listing: listing.contents)
+        return d
+
 
 class CloudShareSet(ShareSet):
     implements(IShareSet)
index 5255cdfe5ffd8e448e9b070e2a03777dde6fe9c3..a82d51b0e7652233d836c2e2dd0ad9b9980061b3 100644 (file)
@@ -118,6 +118,12 @@ class DiskBackend(Backend):
         # so must use its TubID as a permutation-seed.
         return bool(set(fileutil.listdir(self._sharedir)) - set(["incoming"]))
 
+    def list_container(self, prefix=''):
+        def _not_implemented():
+            raise NotImplementedError("the disk backend does not support listing container contents.\n" +
+                                      "Use 'tahoe debug catalog-shares' instead.")
+        return defer.execute(_not_implemented)
+
 
 class DiskShareSet(ShareSet):
     implements(IShareSet)
index b8e80c3dbba5a6213ed007c64ead5e53447872ee..baee824a9d42629d0fbf2e812ea61524abe67369 100644 (file)
@@ -6,9 +6,11 @@ from allmydata.interfaces import IStorageBackend, IShareSet, IShareBase, \
     IShareForReading, IShareForWriting, IMutableShare
 
 from allmydata.util.assertutil import precondition
+from allmydata.util.listutil import concat
 from allmydata.storage.backends.base import Backend, ShareSet, empty_check_testv
 from allmydata.storage.bucket import BucketWriter
 from allmydata.storage.common import si_b2a
+from allmydata.storage.backends.base import ContainerItem
 
 
 def configure_null_backend(storedir, config):
@@ -51,6 +53,9 @@ class NullBackend(Backend):
     def fill_in_space_stats(self, stats):
         pass
 
+    def list_container(self, prefix=''):
+        return defer.succeed(concat([s._list_items() for s in self.get_sharesets_for_prefix(prefix)]))
+
 
 class NullShareSet(ShareSet):
     implements(IShareSet)
@@ -69,6 +74,11 @@ class NullShareSet(ShareSet):
     def get_overhead(self):
         return 0
 
+    def _list_items(self):
+        sistr = si_b2a(self.storage_index)
+        return [ContainerItem("shares/%s/%s/%d" % (sistr[:2], sistr, shnum), None, "", 0, "STANDARD", None)
+                for shnum in set.union(self._immutable_shnums, self._mutable_shnums)]
+
     def _locked_get_shares(self):
         shares = {}
         for shnum in self._immutable_shnums: