Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tests/__init__.py
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | if rels: | ||||
if not_found: | if not_found: | ||||
missing_objs = ", ".join( | missing_objs = ", ".join( | ||||
str((object_to_branch[rel], rel.hex())) for rel in not_found | str((object_to_branch[rel], rel.hex())) for rel in not_found | ||||
) | ) | ||||
raise InexistentObjectsError( | raise InexistentObjectsError( | ||||
f"Branch/Release(s) {missing_objs} should exist in storage" | f"Branch/Release(s) {missing_objs} should exist in storage" | ||||
) | ) | ||||
# first level dirs exist? | |||||
dirs = objects_by_target_type.get(TargetType.DIRECTORY) | dirs = objects_by_target_type.get(TargetType.DIRECTORY) | ||||
if dirs: | if dirs: | ||||
not_found = list(storage.directory_missing(dirs)) | not_found = list(storage.directory_missing(dirs)) | ||||
if not_found: | if not_found: | ||||
missing_objs = ", ".join( | missing_objs = ", ".join( | ||||
str((object_to_branch[dir_].hex(), dir_.hex())) for dir_ in not_found | str((object_to_branch[dir_].hex(), dir_.hex())) for dir_ in not_found | ||||
) | ) | ||||
raise InexistentObjectsError( | raise InexistentObjectsError( | ||||
f"Missing directories {missing_objs}: " | f"Missing directories {missing_objs}: " | ||||
"(revision exists, directory target does not)" | "(revision exists, directory target does not)" | ||||
) | ) | ||||
for dir_ in dirs: # retrieve new objects to check for existence | |||||
paths = storage.directory_ls(dir_, recursive=True) | |||||
for path in paths: | |||||
if path["type"] == "dir": | |||||
target_type = TargetType.DIRECTORY | |||||
else: | |||||
target_type = TargetType.CONTENT | |||||
target = path["target"] | |||||
objects_by_target_type[target_type].append(target) | |||||
object_to_branch[target] = dir_ | |||||
# check nested directories | |||||
dirs = objects_by_target_type.get(TargetType.DIRECTORY) | |||||
if dirs: | |||||
not_found = list(storage.directory_missing(dirs)) | |||||
if not_found: | |||||
missing_objs = ", ".join( | |||||
str((object_to_branch[dir_].hex(), dir_.hex())) for dir_ in not_found | |||||
) | |||||
raise InexistentObjectsError( | |||||
f"Missing directories {missing_objs}: " | |||||
"(revision exists, directory target does not)" | |||||
) | |||||
# check contents directories | |||||
cnts = objects_by_target_type.get(TargetType.CONTENT) | |||||
if cnts: | |||||
not_found = list(storage.content_missing_per_sha1_git(cnts)) | |||||
if not_found: | |||||
missing_objs = ", ".join( | |||||
str((object_to_branch[cnt].hex(), cnt.hex())) for cnt in not_found | |||||
) | |||||
raise InexistentObjectsError(f"Missing contents {missing_objs}") | |||||
# for retro compat, returned the dict, remove when clients are migrated | # for retro compat, returned the dict, remove when clients are migrated | ||||
return snapshot_dict | return snapshot_dict | ||||
def get_stats(storage) -> Dict: | def get_stats(storage) -> Dict: | ||||
"""Adaptation utils to unify the stats counters across storage | """Adaptation utils to unify the stats counters across storage | ||||
implementation. | implementation. | ||||
Show All 17 Lines |