From dc42e1c9590fe239e37f2218d115a4ea810f9882 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 31 Aug 2008 06:17:44 -0400 Subject: [PATCH] Make readdir() a method of TreeKey. Signed-off-by: Anders Kaseorg --- routefs/__init__.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/routefs/__init__.py b/routefs/__init__.py index 1abbf9a..bd7fa7b 100644 --- a/routefs/__init__.py +++ b/routefs/__init__.py @@ -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 -- 1.7.9.5