Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/backends/libcloud.py
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | def add(self, content, obj_id=None, check_presence=True): | ||||
self._put_object(content, obj_id) | self._put_object(content, obj_id) | ||||
return obj_id | return obj_id | ||||
def restore(self, content, obj_id=None): | def restore(self, content, obj_id=None): | ||||
return self.add(content, obj_id, check_presence=False) | return self.add(content, obj_id, check_presence=False) | ||||
def get(self, obj_id): | def get(self, obj_id): | ||||
obj = b''.join(self._get_object(obj_id).as_stream()) | obj = b''.join(self._get_object(obj_id).as_stream()) | ||||
return decompressors[self.compression](obj) | d = decompressors[self.compression]() | ||||
ret = d.decompress(obj) | |||||
if d.unused_data: | |||||
hex_obj_id = hashutil.hash_to_hex(obj_id) | |||||
raise Error('Corrupt object %s: trailing data found' % hex_obj_id) | |||||
return ret | |||||
def check(self, obj_id): | def check(self, obj_id): | ||||
# Check that the file exists, as _get_object raises ObjNotFoundError | # Check that the file exists, as _get_object raises ObjNotFoundError | ||||
self._get_object(obj_id) | self._get_object(obj_id) | ||||
# Check the content integrity | # Check the content integrity | ||||
obj_content = self.get(obj_id) | obj_content = self.get(obj_id) | ||||
content_obj_id = compute_hash(obj_content) | content_obj_id = compute_hash(obj_content) | ||||
if content_obj_id != obj_id: | if content_obj_id != obj_id: | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |