Exemplo n.º 1
0
    def getattr(self, path, fh=None):
        '''
        Returns a dictionary with keys identical to the stat C structure of
        stat(2).

        st_atime, st_mtime and st_ctime should be floats.

        NOTE: There is an incombatibility between Linux and Mac OS X
        concerning st_nlink of directories. Mac OS X counts all files inside
        the directory, while Linux counts only the subdirectories.
        '''
        if path == '/':
            st_nlink = 2 + len(self._all_dbs)
            return {
                'st_mode': (stat.S_IFDIR | 0o755),
                'st_nlink': st_nlink,
            }

        doc = self._get_doc(path[1:])

        # stat attrs
        file_type = stat.S_IFREG
        st_nlink = 1
        st_size = 0

        if is_db(doc):
            file_type = stat.S_IFDIR
            st_nlink = 2
            st_size = 4096
        elif is_doc(doc):
            file_type = stat.S_IFREG
            st_nlink = 1
            st_size = len(self._get_doc_formated(doc))

        return {
            'st_mode': (file_type | 0o755),
            'st_nlink': st_nlink,
            'st_size': st_size,
        }
Exemplo n.º 2
0
    def readdir(self, path, fh):
        '''
        Can return either a list of names, or a list of (name, attrs, offset)
        tuples. attrs is a dict as in getattr.
        '''
        ret = ('.', '..')

        if path == '/':
            return ret + tuple(self._all_dbs)

        doc = self._get_doc(path[1:])

        if is_db(doc):
            db = self.account[doc['db_name']]
            docs = tuple(map(
                lambda x: '{}.json'.format(x['id']),
                filter(
                    lambda x: False if x['id'].startswith('_design/') else True,
                    db.all_docs()
                )
            ))
            self.log.debug('All docs of {}: {}'.format(db.uri, docs))
            return ret + docs