Make readdir() a method of TreeKey.
authorAnders Kaseorg <andersk@mit.edu>
Sun, 31 Aug 2008 10:17:44 +0000 (06:17 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Fri, 5 Sep 2008 00:25:24 +0000 (20:25 -0400)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>

routefs/__init__.py

index 1abbf9a..bd7fa7b 100644 (file)
@@ -97,12 +97,7 @@ class RouteFS(fuse.Fuse):
         If the path referred to is a directory, return the elements of
         that diectory
         """
-        obj = self._get_file(path)
-        if type(obj) is not Directory:
-            return
-        else:
-            for member in ['.', '..'] + obj:
-                yield fuse.Direntry(str(member))
+        return self._get_file(path).readdir(offset)
     
     def getattr(self, path):
         """
@@ -141,10 +136,14 @@ class RouteFS(fuse.Fuse):
 class TreeKey(object):
     def getattr(self):
         return -errno.EINVAL
+    def readdir(self, offset):
+        return -errno.EINVAL
 
 class NoEntry(TreeKey):
     def getattr(self):
         return -errno.ENOENT
+    def readdir(self, offset):
+        return -errno.ENOENT
 
 class TreeEntry(TreeKey):
     default_mode = 0444
@@ -173,6 +172,10 @@ class Directory(TreeEntry, list):
         st.st_nlink = 2
         return st
 
+    def readdir(self, offset):
+        for member in ['.', '..'] + self:
+            yield fuse.Direntry(str(member))
+
 class Symlink(TreeEntry, str):
     """
     A dummy class representing something that should be a symlink