in atr/tasks/checks/targz.py [0:0]
def root_directory(tgz_path: str) -> str:
"""Find the root directory in a tar archive and validate that it has only one root dir."""
root = None
with tarfile.open(tgz_path, mode="r|gz") as tf:
for member in tf:
if member.name and member.name.split("/")[-1].startswith("._"):
# Metadata convention
continue
parts = member.name.split("/", 1)
if len(parts) >= 1:
if not root:
root = parts[0]
elif parts[0] != root:
raise ValueError(f"Multiple root directories found: {root}, {parts[0]}")
if not root:
raise ValueError("No root directory found in archive")
return root