import hashlib
import binascii
-from base import NotAllowedError, BaseBackend
+from base import NotAllowedError, QuotaError, BaseBackend
from lib.hashfiler import Mapper, Blocker
( CLUSTER_NORMAL, CLUSTER_HISTORY, CLUSTER_DELETED ) = range(3)
for x in ['ROOTNODE', 'SERIAL', 'HASH', 'SIZE', 'MTIME', 'MUSER', 'CLUSTER']:
setattr(self, x, getattr(self.mod.node, x))
+ def close(self):
+ self.wrapper.close()
+
@backend_method
def list_accounts(self, user, marker=None, limit=10000):
"""Return a list of accounts the user can access."""
self._put_policy(node, policy, replace)
@backend_method
- def put_account(self, user, account, policy=None):
+ def put_account(self, user, account, policy={}):
"""Create a new account with the given name."""
logger.debug("put_account: %s %s", account, policy)
self._put_policy(node, policy, replace)
@backend_method
- def put_container(self, user, account, container, policy=None):
+ def put_container(self, user, account, container, policy={}):
"""Create a new container with the given name."""
logger.debug("put_container: %s %s %s", account, container, policy)
# Check quota.
size_delta = size # Change with versioning.
if size_delta > 0:
- account_quota = self._get_policy(account_node)['quota']
- container_quota = self._get_policy(container_node)['quota']
+ account_quota = long(self._get_policy(account_node)['quota'])
+ container_quota = long(self._get_policy(container_node)['quota'])
if (account_quota > 0 and self._get_statistics(account_node)[1] + size_delta > account_quota) or \
(container_quota > 0 and self._get_statistics(container_node)[1] + size_delta > container_quota):
# This must be executed in a transaction, so the version is never created if it fails.
- raise
+ raise QuotaError
if not replace_meta and src_version_id is not None:
self.node.attribute_copy(src_version_id, dest_version_id)
"""Create/update an object with the specified size and partial hashes."""
logger.debug("update_object_hashmap: %s %s %s %s %s", account, container, name, size, hashmap)
+ if size == 0: # No such thing as an empty hashmap.
+ hashmap = [self.put_block('')]
map = HashMap(self.block_size, self.hash_algorithm)
map.extend([binascii.unhexlify(x) for x in hashmap])
missing = self.blocker.block_ping(map)