Chris Beaven avatar Chris Beaven committed c96cf44

Add a full_listdir method for CloudFilesStorage which returns directory names as well (the default listdir method uses the cloudfiles' list_objects(path=...) method, which does not return directories)

Comments (0)

Files changed (1)


     Custom storage for Mosso Cloud Files.
+    default_quick_listdir = True
     def __init__(self, username=None, api_key=None, container=None):
     def listdir(self, path):
+        Lists the contents of the specified path, returning a 2-tuple; the
+        first being an empty list of directories (not available for quick-
+        listing), the second being a list of filenames.
+        If the list of directories is required, use the full_listdir method.
+        """
+        return ([], self.container.list_objects(path=path))
+    def full_listdir(self, path):
+        """
         Lists the contents of the specified path, returning a 2-tuple of lists;
         the first item being directories, the second item being files.
+        On large containers, this may be a slow operation for root containers
+        because every single object must be returned (cloudfiles does not
+        provide an explicit way of listing directories).
-        return ([], self.container.list_objects(path=path))
+        dirs = set()
+        files = []
+        if path and not path.endswith('/'):
+            path = '%s/' % path
+        path_len = len(path)
+        for name in self.container.list_objects(prefix=path):
+            name = name[path_len:]
+            slash = name[1:-1].find('/') + 1
+            if slash:
+                dirs.add(name[:slash])
+            elif name:
+                files.append(name)
+        dirs = list(dirs)
+        dirs.sort()
+        return (dirs, files)
     def size(self, name):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.