def _license_files_check_core_logic_zip()

in atr/tasks/checks/zipformat.py [0:0]


def _license_files_check_core_logic_zip(artifact_path: str) -> dict[str, Any]:
    """Verify LICENSE and NOTICE files within a zip archive."""
    # TODO: Obviously we want to reuse the license files check logic from license.py
    # But we'd need to have task dependencies to do that, ideally
    try:
        with zipfile.ZipFile(artifact_path, "r") as zf:
            members = zf.namelist()
            if not members:
                return {"error": "Archive is empty"}

            root_dir = _license_files_find_root_dir_zip(members)
            # _LOGGER.info(f"Root dir of {artifact_path}: {root_dir}")
            if not root_dir:
                return {"error": "Could not determine root directory"}

            expected_license_path = root_dir + "/LICENSE"
            expected_notice_path = root_dir + "/NOTICE"

            member_set = set(members)

            license_found, license_valid = (
                _license_files_check_file_zip(zf, artifact_path, expected_license_path)
                if (expected_license_path in member_set)
                else (False, False)
            )
            notice_found, notice_valid = (
                _license_files_check_file_zip(zf, artifact_path, expected_notice_path)
                if (expected_notice_path in member_set)
                else (False, False)
            )

            return {
                "root_dir": root_dir,
                "license_found": license_found,
                "license_valid": license_valid,
                "notice_found": notice_found,
                "notice_valid": notice_valid,
            }

    except zipfile.BadZipFile as e:
        return {"error": f"Bad zip file: {e}"}
    except FileNotFoundError:
        return {"error": "File not found"}
    except Exception as e:
        return {"error": f"Unexpected error: {e}"}