618 |
618 |
prev_meta = backend.get_object_meta(request.user, v_account, v_container, v_object)
|
619 |
619 |
except NameError:
|
620 |
620 |
raise ItemNotFound('Object does not exist')
|
621 |
|
|
622 |
|
# Handle metadata changes.
|
623 |
|
if len(meta) != 0:
|
624 |
|
# Keep previous values of 'Content-Type' and 'hash'.
|
|
621 |
# If replacing, keep previous values of 'Content-Type' and 'hash'.
|
|
622 |
replace = True
|
|
623 |
if 'update' in request.GET:
|
|
624 |
replace = False
|
|
625 |
if replace:
|
625 |
626 |
for k in ('Content-Type', 'hash'):
|
626 |
627 |
if k in prev_meta:
|
627 |
628 |
meta[k] = prev_meta[k]
|
628 |
|
try:
|
629 |
|
backend.update_object_meta(request.user, v_account, v_container, v_object, meta, replace=True)
|
630 |
|
except NameError:
|
631 |
|
raise ItemNotFound('Object does not exist')
|
632 |
629 |
|
633 |
|
# Handle permission changes.
|
634 |
|
if permissions:
|
|
630 |
# A Content-Type header indicates data updates.
|
|
631 |
if not content_type or content_type != 'application/octet-stream':
|
|
632 |
# Handle metadata changes.
|
635 |
633 |
try:
|
636 |
|
backend.update_object_permissions(request.user, v_account, v_container, v_object, permissions)
|
|
634 |
backend.update_object_meta(request.user, v_account, v_container, v_object, meta, replace)
|
637 |
635 |
except NameError:
|
638 |
|
raise ItemNotFound('Object does not exist')
|
639 |
|
except ValueError:
|
640 |
|
raise BadRequest('Invalid sharing header')
|
641 |
|
except AttributeError:
|
642 |
|
raise Conflict('Sharing already set above or below this path in the hierarchy')
|
643 |
|
|
644 |
|
# TODO: Merge above functions with updating the hashmap if there is data in the request.
|
645 |
|
|
646 |
|
# A Content-Type or Content-Range header may indicate data updates.
|
647 |
|
if content_type is None:
|
648 |
|
return HttpResponse(status=202)
|
649 |
|
if content_type.startswith('multipart/byteranges'):
|
650 |
|
# TODO: Support multiple update ranges.
|
|
636 |
raise ItemNotFound('Object does not exist')
|
|
637 |
# Handle permission changes.
|
|
638 |
if permissions:
|
|
639 |
try:
|
|
640 |
backend.update_object_permissions(request.user, v_account, v_container, v_object, permissions)
|
|
641 |
except NameError:
|
|
642 |
raise ItemNotFound('Object does not exist')
|
|
643 |
except ValueError:
|
|
644 |
raise BadRequest('Invalid sharing header')
|
|
645 |
except AttributeError:
|
|
646 |
raise Conflict('Sharing already set above or below this path in the hierarchy')
|
651 |
647 |
return HttpResponse(status=202)
|
|
648 |
|
652 |
649 |
# Single range update. Range must be in Content-Range.
|
653 |
650 |
# Based on: http://code.google.com/p/gears/wiki/ContentRangePostProposal
|
654 |
651 |
# (with the addition that '*' is allowed for the range - will append).
|
655 |
|
if content_type != 'application/octet-stream':
|
656 |
|
return HttpResponse(status=202)
|
657 |
652 |
content_range = request.META.get('HTTP_CONTENT_RANGE')
|
658 |
653 |
if not content_range:
|
659 |
|
return HttpResponse(status=202)
|
|
654 |
raise BadRequest('Missing Content-Range header')
|
660 |
655 |
ranges = get_content_range(request)
|
661 |
656 |
if not ranges:
|
662 |
|
return HttpResponse(status=202)
|
|
657 |
raise RangeNotSatisfiable('Invalid Content-Range header')
|
663 |
658 |
# Require either a Content-Length, or 'chunked' Transfer-Encoding.
|
664 |
659 |
content_length = -1
|
665 |
660 |
if request.META.get('HTTP_TRANSFER_ENCODING') != 'chunked':
|
... | ... | |
696 |
691 |
|
697 |
692 |
if offset > size:
|
698 |
693 |
size = offset
|
699 |
|
meta = {'hash': hashmap_hash(hashmap)} # Update ETag.
|
|
694 |
meta.update({'hash': hashmap_hash(hashmap)}) # Update ETag.
|
700 |
695 |
try:
|
701 |
|
backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, False)
|
|
696 |
backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, replace, permissions)
|
702 |
697 |
except NameError:
|
703 |
698 |
raise ItemNotFound('Container does not exist')
|
704 |
699 |
except ValueError:
|