Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/backends/pathslicing.py
Show All 14 Lines | |||||
from swh.objstorage.exc import Error, ObjNotFoundError | from swh.objstorage.exc import Error, ObjNotFoundError | ||||
from swh.objstorage.objstorage import ( | from swh.objstorage.objstorage import ( | ||||
DEFAULT_CHUNK_SIZE, | DEFAULT_CHUNK_SIZE, | ||||
DEFAULT_LIMIT, | DEFAULT_LIMIT, | ||||
ID_HASH_ALGO, | ID_HASH_ALGO, | ||||
ID_HEXDIGEST_LENGTH, | ID_HEXDIGEST_LENGTH, | ||||
ObjStorage, | ObjStorage, | ||||
compressors, | compressors, | ||||
compute_hash, | |||||
decompressors, | decompressors, | ||||
) | ) | ||||
BUFSIZ = 1048576 | BUFSIZ = 1048576 | ||||
DIR_MODE = 0o755 | DIR_MODE = 0o755 | ||||
FILE_MODE = 0o644 | FILE_MODE = 0o644 | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | def __len__(self): | ||||
Warning: this currently uses `__iter__`, its warning about bad | Warning: this currently uses `__iter__`, its warning about bad | ||||
performances applies | performances applies | ||||
Return: | Return: | ||||
number of objects contained in the storage | number of objects contained in the storage | ||||
""" | """ | ||||
return sum(1 for i in self) | return sum(1 for i in self) | ||||
def add(self, content, obj_id=None, check_presence=True): | def add(self, content, obj_id, check_presence=True): | ||||
if obj_id is None: | |||||
obj_id = compute_hash(content) | |||||
if check_presence and obj_id in self: | if check_presence and obj_id in self: | ||||
# If the object is already present, return immediately. | # If the object is already present, return immediately. | ||||
return obj_id | return obj_id | ||||
hex_obj_id = hashutil.hash_to_hex(obj_id) | hex_obj_id = hashutil.hash_to_hex(obj_id) | ||||
if not isinstance(content, Iterator): | if not isinstance(content, Iterator): | ||||
content = [content] | content = [content] | ||||
compressor = compressors[self.compression]() | compressor = compressors[self.compression]() | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |