예제 #1
0
파일: couch.py 프로젝트: iblis17/couchfs
    def _get_doc(self, path, raw=False, check_doc=False,
                 formated=False) -> dict or str:
        '''
        :param raw: with the args, we just return the ``response`` object
        :param check_doc: Checking the body is a regular doc,
                it should be able to decoded.
                (via utils.is_doc)
        :param formated: body in beautiful form
        :return: the document in json.
                If the doc is unable to decode,
                we return the raw text.
        '''
        assert not (raw and is_doc), (
            'param raw and is_doc are mutually exclusive')
        assert not (raw and formated), (
            'param raw and formated are mutually exclusive')

        res = self.account.get(self._get_doc_id(path))
        code = res.status_code

        if code == http.client.NOT_FOUND:
            raise FuseOSError(ENOENT)
        elif code != http.client.OK:
            self.log.debug('strang status {}'.format(code))
            self.log.debug('content {}{}'.format(
                res.text[:200]),
                ' ...' if len(res.text) > 200 else None
            )

        if raw:
            return res

        body = self._get_doc_body(res)

        if check_doc and not is_doc(body):
            raise FuseOSError(EIO)

        if formated:
            return self._get_doc_formated(body)

        return body
예제 #2
0
파일: couch.py 프로젝트: iblis17/couchfs
    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,
        }