Commit 70c02c4d authored by Antony Chazapis's avatar Antony Chazapis
Browse files

Fix account/container size reporting, zero-length object uploading.

parent fb19cc80
......@@ -423,18 +423,24 @@ def object_write(request, v_account, v_container, v_object):
if 'Content-Type' not in meta:
raise LengthRequired('Missing Content-Type header')
sock = raw_input_socket(request)
md5 = hashlib.md5()
offset = 0
for data in socket_read_iterator(sock, content_length):
# TODO: Raise 408 (Request Timeout) if this takes too long.
# TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
md5.update(data)
if content_length == 0:
try:
backend.update_object(request.user, v_container, v_object, data, offset)
backend.update_object(request.user, v_container, v_object, '')
except NameError:
raise ItemNotFound('Object does not exist')
offset += len(data)
raise ItemNotFound('Container does not exist')
else:
sock = raw_input_socket(request)
offset = 0
for data in socket_read_iterator(sock, content_length):
# TODO: Raise 408 (Request Timeout) if this takes too long.
# TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
md5.update(data)
try:
backend.update_object(request.user, v_container, v_object, data, offset)
except NameError:
raise ItemNotFound('Container does not exist')
offset += len(data)
meta['hash'] = md5.hexdigest().lower()
etag = request.META.get('HTTP_ETAG')
......
......@@ -38,7 +38,9 @@ class SimpleBackend(BaseBackend):
return {'name': account, 'count': 0, 'bytes': 0}
contents = os.listdir(fullname)
count = len(contents)
size = sum((os.path.getsize(os.path.join(fullname, x)) for x in os.listdir(fullname)))
size = 0
for y in (os.path.join(fullname, z) for z in contents):
size += sum((os.path.getsize(os.path.join(y, x)) for x in os.listdir(y)))
meta = self._get_metadata(account)
meta.update({'name': account, 'count': count, 'bytes': size})
return meta
......@@ -81,7 +83,7 @@ class SimpleBackend(BaseBackend):
fullname = self._get_containerinfo(account, name)
contents = os.listdir(fullname)
count = len(contents)
size = os.stat(fullname).st_size
size = sum((os.path.getsize(os.path.join(fullname, x)) for x in contents))
meta = self._get_metadata(os.path.join(account, name))
meta.update({'name': name, 'count': count, 'bytes': size})
return meta
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment