diff --git a/favro_sync/favro_fuse.py b/favro_sync/favro_fuse.py index 1b4ef66..cd17978 100644 --- a/favro_sync/favro_fuse.py +++ b/favro_sync/favro_fuse.py @@ -168,13 +168,16 @@ class FavroFuse(fuse.Fuse): def __init__( self, + *, favro_client: FavroClient, formatter: CardFileFormatter, + collection_filter: frozenset[str], **kwargs, ): self.favro_client = favro_client self.formatter = formatter self.wiped_cards = set() + self.collection_filter = collection_filter self.path_components = [ RootFileSystemItem, CollectionFileSystemItem, @@ -209,6 +212,9 @@ class FavroFuse(fuse.Fuse): return -errno.ENOENT return st + def _is_allowed_collection(self, item: CollectionFileSystemItem) -> bool: + return item.collection_name in self.collection_filter + def readdir(self, path: str, offset: int) -> Iterator[fuse.Direntry]: logger.info('Reading directory: %s', path) file_system_item = path_to_file_system_item(path, self.path_components) @@ -218,11 +224,15 @@ class FavroFuse(fuse.Fuse): if isinstance(file_system_item, RootFileSystemItem): for collection in self.favro_client.get_collections(): - collection_name = collection.name.replace('/', '') - yield fuse.Direntry(str(CollectionFileSystemItem(collection_name))) - del collection + item = CollectionFileSystemItem(collection.name.replace('/', '')) + if self._is_allowed_collection(item): + yield fuse.Direntry(str(item)) + del collection, item elif isinstance(file_system_item, CollectionFileSystemItem): + if not self._is_allowed_collection(file_system_item): + return # Yield nothing + # TODO: move into own function for collection in self.favro_client.get_collections(): if collection.name.replace('/', '') == file_system_item.collection_name: @@ -339,10 +349,12 @@ Userspace hello example def start_favro_fuse(favro_client: FavroClient): logger.info('Starting favro FUSE') + collection_filter = frozenset(['Platform']) # TODO: server = FavroFuse( favro_client=favro_client, formatter=CardFileFormatter(), + collection_filter=collection_filter, version='%prog ' + fuse.__version__, usage=HELP, dash_s_do='setsingle',