Revision fac5f6be
b/snf-pithos-app/pithos/api/functions.py | ||
---|---|---|
66 | 66 |
|
67 | 67 |
from pithos.backends.base import ( |
68 | 68 |
NotAllowedError, QuotaError, ContainerNotEmpty, ItemNotExists, |
69 |
VersionNotExists, ContainerExists, InvalidHash) |
|
69 |
VersionNotExists, ContainerExists, InvalidHash, IllegalOperationError)
|
|
70 | 70 |
|
71 | 71 |
from pithos.backends.filter import parse_filters |
72 | 72 |
|
... | ... | |
1115 | 1115 |
request.user_uniq, v_account, v_container, v_object, size, |
1116 | 1116 |
content_type, hashmap, checksum, 'pithos', meta, True, permissions |
1117 | 1117 |
) |
1118 |
except IllegalOperationError, e: |
|
1119 |
raise faults.Forbidden(e[0]) |
|
1118 | 1120 |
except NotAllowedError: |
1119 | 1121 |
raise faults.Forbidden('Not allowed') |
1120 | 1122 |
except IndexError, e: |
... | ... | |
1176 | 1178 |
request.user_uniq, v_account, v_container, v_object, file.size, |
1177 | 1179 |
file.content_type, file.hashmap, checksum, 'pithos', {}, True |
1178 | 1180 |
) |
1181 |
except IllegalOperationError, e: |
|
1182 |
faults.Forbidden(e[0]) |
|
1179 | 1183 |
except NotAllowedError: |
1180 | 1184 |
raise faults.Forbidden('Not allowed') |
1181 | 1185 |
except ItemNotExists: |
... | ... | |
1437 | 1441 |
hashmap[bi] = src_hashmap[sbi] |
1438 | 1442 |
else: |
1439 | 1443 |
data = request.backend.get_block(src_hashmap[sbi]) |
1440 |
hashmap[bi] = request.backend.update_block( |
|
1441 |
hashmap[bi], data[:bl], 0) |
|
1444 |
try: |
|
1445 |
hashmap[bi] = request.backend.update_block( |
|
1446 |
hashmap[bi], data[:bl], 0) |
|
1447 |
except IllegalOperationError, e: |
|
1448 |
raise faults.Forbidden(e[0]) |
|
1442 | 1449 |
else: |
1443 | 1450 |
hashmap.append(src_hashmap[sbi]) |
1444 | 1451 |
offset += bl |
... | ... | |
1485 | 1492 |
prev_meta['type'], hashmap, checksum, 'pithos', meta, replace, |
1486 | 1493 |
permissions |
1487 | 1494 |
) |
1495 |
except IllegalOperationError, e: |
|
1496 |
raise faults.Forbidden(e[0]) |
|
1488 | 1497 |
except NotAllowedError: |
1489 | 1498 |
raise faults.Forbidden('Not allowed') |
1490 | 1499 |
except ItemNotExists: |
b/snf-pithos-app/pithos/api/util.py | ||
---|---|---|
72 | 72 |
from pithos.api.resources import resources |
73 | 73 |
from pithos.backends import connect_backend |
74 | 74 |
from pithos.backends.base import (NotAllowedError, QuotaError, ItemNotExists, |
75 |
VersionNotExists) |
|
75 |
VersionNotExists, IllegalOperationError)
|
|
76 | 76 |
|
77 | 77 |
from synnefo.lib import join_urls |
78 | 78 |
from synnefo.util import text |
... | ... | |
967 | 967 |
bo = offset % request.backend.block_size |
968 | 968 |
bl = min(len(data), request.backend.block_size - bo) |
969 | 969 |
if bi < len(hashmap): |
970 |
hashmap[bi] = request.backend.update_block(hashmap[bi], data[:bl], bo) |
|
970 |
try: |
|
971 |
hashmap[bi] = request.backend.update_block(hashmap[bi], |
|
972 |
data[:bl], bo) |
|
973 |
except IllegalOperationError, e: |
|
974 |
raise faults.Forbidden(e) |
|
971 | 975 |
else: |
972 | 976 |
hashmap.append(request.backend.put_block(('\x00' * bo) + data[:bl])) |
973 | 977 |
return bl # Return ammount of data written. |
b/snf-pithos-backend/pithos/backends/base.py | ||
---|---|---|
41 | 41 |
pass |
42 | 42 |
|
43 | 43 |
|
44 |
class IllegalOperationError(NotAllowedError): |
|
45 |
pass |
|
46 |
|
|
47 |
|
|
44 | 48 |
class QuotaError(Exception): |
45 | 49 |
pass |
46 | 50 |
|
... | ... | |
68 | 72 |
class VersionNotExists(IndexError): |
69 | 73 |
pass |
70 | 74 |
|
75 |
|
|
71 | 76 |
class InvalidHash(TypeError): |
72 | 77 |
pass |
73 | 78 |
|
79 |
|
|
74 | 80 |
class BaseBackend(object): |
75 | 81 |
"""Abstract backend class. |
76 | 82 |
|
b/snf-pithos-backend/pithos/backends/modular.py | ||
---|---|---|
49 | 49 |
DEFAULT_CONTAINER_VERSIONING, NotAllowedError, QuotaError, |
50 | 50 |
BaseBackend, AccountExists, ContainerExists, AccountNotEmpty, |
51 | 51 |
ContainerNotEmpty, ItemNotExists, VersionNotExists, |
52 |
InvalidHash) |
|
52 |
InvalidHash, IllegalOperationError)
|
|
53 | 53 |
|
54 | 54 |
|
55 | 55 |
class DisabledAstakosClient(object): |
... | ... | |
1040 | 1040 |
props = self._get_version(node, version) |
1041 | 1041 |
if props[self.HASH] is None: |
1042 | 1042 |
return 0, () |
1043 |
hashmap = self.store.map_get(self._unhexlify_hash(props[self.HASH])) |
|
1044 |
return props[self.SIZE], [binascii.hexlify(x) for x in hashmap] |
|
1043 |
if props[self.HASH].startswith('archip:'): |
|
1044 |
hashmap = self.store.map_get_archipelago(props[self.HASH], |
|
1045 |
props[self.SIZE]) |
|
1046 |
return props[self.SIZE], [x for x in hashmap] |
|
1047 |
else: |
|
1048 |
hashmap = self.store.map_get(self._unhexlify_hash( |
|
1049 |
props[self.HASH])) |
|
1050 |
return props[self.SIZE], [binascii.hexlify(x) for x in hashmap] |
|
1045 | 1051 |
|
1046 | 1052 |
def _update_object_hash(self, user, account, container, name, size, type, |
1047 | 1053 |
hash, checksum, domain, meta, replace_meta, |
... | ... | |
1121 | 1127 |
replace_meta=False, permissions=None): |
1122 | 1128 |
"""Create/update an object's hashmap and return the new version.""" |
1123 | 1129 |
|
1130 |
for h in hashmap: |
|
1131 |
if h.startswith('archip_'): |
|
1132 |
raise IllegalOperationError( |
|
1133 |
'Cannot update Archipelago Volume hashmap.') |
|
1124 | 1134 |
meta = meta or {} |
1125 | 1135 |
if size == 0: # No such thing as an empty hashmap. |
1126 | 1136 |
hashmap = [self.put_block('')] |
... | ... | |
1409 | 1419 |
"""Return a block's data.""" |
1410 | 1420 |
|
1411 | 1421 |
logger.debug("get_block: %s", hash) |
1412 |
block = self.store.block_get(self._unhexlify_hash(hash)) |
|
1422 |
if hash.startswith('archip_'): |
|
1423 |
block = self.store.block_get_archipelago(hash) |
|
1424 |
else: |
|
1425 |
block = self.store.block_get(self._unhexlify_hash(hash)) |
|
1413 | 1426 |
if not block: |
1414 | 1427 |
raise ItemNotExists('Block does not exist') |
1415 | 1428 |
return block |
... | ... | |
1424 | 1437 |
"""Update a known block and return the hash.""" |
1425 | 1438 |
|
1426 | 1439 |
logger.debug("update_block: %s %s %s", hash, len(data), offset) |
1440 |
if hash.startswith('archip_'): |
|
1441 |
raise IllegalOperationError( |
|
1442 |
'Cannot update an Archipelago Volume block.') |
|
1427 | 1443 |
if offset == 0 and len(data) == self.block_size: |
1428 | 1444 |
return self.put_block(data) |
1429 | 1445 |
h = self.store.block_update(self._unhexlify_hash(hash), offset, data) |
Also available in: Unified diff