示例#1
0
文件: fs.py 项目: AthinaB/synnefo
    def object_getattr(self, container, object, fh=None):
        meta = self._get_object_meta(container, object)
        modified = parse_http_date(meta['last-modified'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))
        size = int(meta.get('content-length', 0))

        if meta['content-type'].split(';', 1)[0].strip() == 'application/directory':
            mode = int(meta.get('x-object-meta-mode', 0755))
            flags = S_IFDIR
            nlink = 2
        else:
            mode = int(meta.get('x-object-meta-mode', 0644))
            flags = S_IFREG
            nlink = 1

        return {
            'st_mode': flags | mode,
            'st_nlink': nlink,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified,
            'st_size': size}
示例#2
0
文件: fs.py 项目: salsa-dev/synnefo
    def object_getattr(self, container, object, fh=None):
        meta = self._get_object_meta(container, object)
        modified = parse_http_date(meta['last-modified'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))
        size = int(meta.get('content-length', 0))

        if meta['content-type'].split(';',
                                      1)[0].strip() == 'application/directory':
            mode = int(meta.get('x-object-meta-mode', 0755))
            flags = S_IFDIR
            nlink = 2
        else:
            mode = int(meta.get('x-object-meta-mode', 0644))
            flags = S_IFREG
            nlink = 1

        return {
            'st_mode': flags | mode,
            'st_nlink': nlink,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified,
            'st_size': size
        }
示例#3
0
def object_data_response(request, sizes, hashmaps, meta, public=False):
    """Get the HttpResponse object for replying with the object's data."""

    # Range handling.
    size = sum(sizes)
    ranges = get_range(request, size)
    if ranges is None:
        ranges = [(0, size)]
        ret = 200
    else:
        check = [
            True for offset, length in ranges if length <= 0 or length > size
            or offset < 0 or offset >= size or offset + length > size
        ]
        if len(check) > 0:
            raise faults.RangeNotSatisfiable(
                'Requested range exceeds object limits')
        ret = 206
        if_range = request.META.get('HTTP_IF_RANGE')
        if if_range:
            try:
                # Modification time has passed instead.
                last_modified = parse_http_date(if_range)
                if last_modified != meta['modified']:
                    ranges = [(0, size)]
                    ret = 200
            except ValueError:
                if if_range != meta['checksum']:
                    ranges = [(0, size)]
                    ret = 200

    if ret == 206 and len(ranges) > 1:
        boundary = uuid.uuid4().hex
    else:
        boundary = ''
    wrapper = ObjectWrapper(request.backend, ranges, sizes, hashmaps, boundary,
                            meta)
    response = HttpResponse(wrapper, status=ret)
    put_object_headers(response,
                       meta,
                       restricted=public,
                       token=getattr(request, 'token', None),
                       disposition_type=request.GET.get('disposition-type'),
                       include_content_disposition=True)
    if ret == 206:
        if len(ranges) == 1:
            offset, length = ranges[0]
            response[
                'Content-Length'] = length  # Update with the correct length.
            response['Content-Range'] = 'bytes %d-%d/%d' % (offset, offset +
                                                            length - 1, size)
        else:
            del (response['Content-Length'])
            response['Content-Type'] = 'multipart/byteranges; boundary=%s' % (
                boundary, )
    return response
示例#4
0
文件: util.py 项目: grnet/synnefo
def object_data_response(request, sizes, hashmaps, meta, public=False):
    """Get the StreamingHttpResponse object for replying with the object's
       data."""

    # Range handling.
    size = sum(sizes)
    ranges = get_range(request, size)
    if ranges is None:
        ranges = [(0, size)]
        ret = 200
    else:
        check = [True for offset, length in ranges if
                 length <= 0 or length > size or
                 offset < 0 or offset >= size or
                 offset + length > size]
        if len(check) > 0:
            raise faults.RangeNotSatisfiable(
                'Requested range exceeds object limits')
        ret = 206
        if_range = request.META.get('HTTP_IF_RANGE')
        if if_range:
            try:
                # Modification time has passed instead.
                last_modified = parse_http_date(if_range)
                if last_modified != meta['modified']:
                    ranges = [(0, size)]
                    ret = 200
            except ValueError:
                if if_range != meta['checksum']:
                    ranges = [(0, size)]
                    ret = 200

    if ret == 206 and len(ranges) > 1:
        boundary = uuid.uuid4().hex
    else:
        boundary = ''
    wrapper = ObjectWrapper(request.backend, ranges, sizes, hashmaps,
                            boundary, meta)
    response = StreamingHttpResponse(wrapper, status=ret)
    put_object_headers(
        response, meta, restricted=public,
        token=getattr(request, 'token', None),
        disposition_type=request.GET.get('disposition-type'),
        include_content_disposition=True)
    if ret == 206:
        if len(ranges) == 1:
            offset, length = ranges[0]
            response[
                'Content-Length'] = length  # Update with the correct length.
            response['Content-Range'] = 'bytes %d-%d/%d' % (
                offset, offset + length - 1, size)
        else:
            del(response['Content-Length'])
            response['Content-Type'] = 'multipart/byteranges; boundary=%s' % (
                boundary,)
    return response
示例#5
0
文件: fs.py 项目: AthinaB/synnefo
    def container_getattr(self, container, fh=None):
        meta = self._get_container_meta(container)
        mode = int(meta.get('x-container-meta-mode', 0755))
        modified = parse_http_date(meta['last-modified'])
        count = int(meta['x-container-object-count'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))

        return {
            'st_mode': S_IFDIR | mode,
            'st_nlink': 2 + count,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified}
示例#6
0
文件: fs.py 项目: AthinaB/synnefo
    def account_getattr(self, fh=None):
        meta = self.client.retrieve_account_metadata()
        mode = int(meta.get('x-account-meta-mode', 0755))
        last_modified = meta.get('last-modified', None)
        modified = parse_http_date(last_modified) if last_modified else epoch
        count = int(meta['x-account-container-count'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))

        return {
            'st_mode': S_IFDIR | mode,
            'st_nlink': 2 + count,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified}
示例#7
0
文件: fs.py 项目: salsa-dev/synnefo
    def container_getattr(self, container, fh=None):
        meta = self._get_container_meta(container)
        mode = int(meta.get('x-container-meta-mode', 0755))
        modified = parse_http_date(meta['last-modified'])
        count = int(meta['x-container-object-count'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))

        return {
            'st_mode': S_IFDIR | mode,
            'st_nlink': 2 + count,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified
        }
示例#8
0
文件: fs.py 项目: salsa-dev/synnefo
    def account_getattr(self, fh=None):
        meta = self.client.retrieve_account_metadata()
        mode = int(meta.get('x-account-meta-mode', 0755))
        last_modified = meta.get('last-modified', None)
        modified = parse_http_date(last_modified) if last_modified else epoch
        count = int(meta['x-account-container-count'])
        uid = int(meta.get('x-account-meta-uid', 0))
        gid = int(meta.get('x-account-meta-gid', 0))

        return {
            'st_mode': S_IFDIR | mode,
            'st_nlink': 2 + count,
            'st_uid': uid,
            'st_gid': gid,
            'st_ctime': epoch,
            'st_mtime': modified,
            'st_atime': modified
        }