Revision 1e47e49d

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
50 50
                  DEFAULT_CONTAINER_VERSIONING, NotAllowedError, QuotaError,
51 51
                  BaseBackend, AccountExists, ContainerExists, AccountNotEmpty,
52 52
                  ContainerNotEmpty, ItemNotExists, VersionNotExists,
53
                  InvalidHash)
53
                  InvalidHash, IllegalOperationError)
54 54

  
55 55

  
56 56
class DisabledAstakosClient(object):
......
1078 1078
        props = self._get_version(node, version)
1079 1079
        if props[self.HASH] is None:
1080 1080
            return 0, ()
1081
        hashmap = self.store.map_get(self._unhexlify_hash(props[self.HASH]))
1082
        return props[self.SIZE], [binascii.hexlify(x) for x in hashmap]
1081
        if props[self.HASH].startswith('archip:'):
1082
            hashmap = self.store.map_get_archipelago(props[self.HASH],
1083
                                                     props[self.SIZE])
1084
            return props[self.SIZE], [x for x in hashmap]
1085
        else:
1086
            hashmap = self.store.map_get(self._unhexlify_hash(
1087
                props[self.HASH]))
1088
            return props[self.SIZE], [binascii.hexlify(x) for x in hashmap]
1083 1089

  
1084 1090
    def _update_object_hash(self, user, account, container, name, size, type,
1085 1091
                            hash, checksum, domain, meta, replace_meta,
......
1159 1165
                              replace_meta=False, permissions=None):
1160 1166
        """Create/update an object's hashmap and return the new version."""
1161 1167

  
1168
        for h in hashmap:
1169
            if h.startswith('archip_'):
1170
                raise IllegalOperationError(
1171
                    'Cannot update Archipelago Volume hashmap.')
1162 1172
        meta = meta or {}
1163 1173
        if size == 0:  # No such thing as an empty hashmap.
1164 1174
            hashmap = [self.put_block('')]
......
1451 1461
        """Return a block's data."""
1452 1462

  
1453 1463
        logger.debug("get_block: %s", hash)
1454
        block = self.store.block_get(self._unhexlify_hash(hash))
1464
        if hash.startswith('archip_'):
1465
            block = self.store.block_get_archipelago(hash)
1466
        else:
1467
            block = self.store.block_get(self._unhexlify_hash(hash))
1455 1468
        if not block:
1456 1469
            raise ItemNotExists('Block does not exist')
1457 1470
        return block
......
1466 1479
        """Update a known block and return the hash."""
1467 1480

  
1468 1481
        logger.debug("update_block: %s %s %s", hash, len(data), offset)
1482
        if hash.startswith('archip_'):
1483
            raise IllegalOperationError(
1484
                'Cannot update an Archipelago Volume block.')
1469 1485
        if offset == 0 and len(data) == self.block_size:
1470 1486
            return self.put_block(data)
1471 1487
        h = self.store.block_update(self._unhexlify_hash(hash), offset, data)

Also available in: Unified diff