Permalink
Browse files

Raise exception on empty archive upload attempt

  • Loading branch information...
1 parent fbb5169 commit 05915453e3887515338ef9c8a062f78c44430058 @petertodd committed Oct 26, 2012
Showing with 12 additions and 0 deletions.
  1. +3 −0 boto/glacier/exceptions.py
  2. +9 −0 boto/glacier/writer.py
@@ -44,3 +44,6 @@ def __init__(self, expected_responses, response):
class UploadArchiveError(Exception):
pass
+
+class EmptyArchiveError(UploadArchiveError):
+ pass
@@ -27,6 +27,7 @@
import math
import json
+from .exceptions import EmptyArchiveError
_ONE_MEGABYTE = 1024 * 1024
@@ -89,6 +90,10 @@ def compute_hashes_from_fileobj(fileobj, chunk_size=1024 * 1024):
linear_hash.update(chunk)
chunks.append(hashlib.sha256(chunk).digest())
chunk = fileobj.read(chunk_size)
+
+ if not chunks:
+ raise EmptyArchiveError()
+
return linear_hash.hexdigest(), bytes_to_hex(tree_hash(chunks))
@@ -156,6 +161,10 @@ def close(self):
return
if self._buffer_size > 0:
self.send_part()
+
+ if not self._tree_hashes:
+ raise EmptyArchiveError()
+
# Complete the multiplart glacier upload
hex_tree_hash = bytes_to_hex(tree_hash(self._tree_hashes))
response = self.vault.layer1.complete_multipart_upload(self.vault.name,

0 comments on commit 0591545

Please sign in to comment.