Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/objstorage_pathslicing.py
Show First 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | def check(self, obj_id): | ||||
'Corrupt object %s should have id %s' | 'Corrupt object %s should have id %s' | ||||
% (hashutil.hash_to_hex(obj_id), | % (hashutil.hash_to_hex(obj_id), | ||||
hashutil.hash_to_hex(actual_obj_id)) | hashutil.hash_to_hex(actual_obj_id)) | ||||
) | ) | ||||
except (OSError, IOError): | except (OSError, IOError): | ||||
# IOError is for compatibility with older python versions | # IOError is for compatibility with older python versions | ||||
raise Error('Corrupt object %s is not a gzip file' % obj_id) | raise Error('Corrupt object %s is not a gzip file' % obj_id) | ||||
def delete(self, obj_id): | |||||
if obj_id not in self: | |||||
raise ObjNotFoundError(obj_id) | |||||
hex_obj_id = hashutil.hash_to_hex(obj_id) | |||||
try: | |||||
os.remove(self._obj_path(hex_obj_id)) | |||||
except FileNotFoundError: | |||||
raise ObjNotFoundError(obj_id) | |||||
return True | |||||
# Management methods | # Management methods | ||||
def get_random(self, batch_size): | def get_random(self, batch_size): | ||||
def get_random_content(self, batch_size): | def get_random_content(self, batch_size): | ||||
""" Get a batch of content inside a single directory. | """ Get a batch of content inside a single directory. | ||||
Returns: | Returns: | ||||
a tuple (batch size, batch). | a tuple (batch size, batch). | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |