verify_package_integrity
Verify integrity of installed Arch Linux package files by comparing checksums, detecting modified, missing, or corrupted files.
Instructions
[MAINTENANCE] Verify the integrity of installed package files. Detects modified, missing, or corrupted files. Only works on Arch Linux. When to use: After system crash or disk errors, verify 'linux' package files match expected checksums.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package_name | Yes | Name of the package to verify | |
| thorough | No | Perform thorough check including file attributes. Default: false |
Implementation Reference
- src/arch_ops_server/pacman.py:1050-1111 (handler)Core handler function that verifies package integrity by running pacman -Qk (or -Qkk for thorough) against a package name. Parses output for warnings/missing files and returns structured results.
async def verify_package_integrity(package_name: str, thorough: bool = False) -> Dict[str, Any]: """ Verify integrity of an installed package. Args: package_name: Name of package to verify thorough: If True, perform thorough check (pacman -Qkk) Returns: Dict with verification results """ if not IS_ARCH: return create_error_response( "NotSupported", "Package verification is only available on Arch Linux" ) if not check_command_exists("pacman"): return create_error_response( "CommandNotFound", "pacman command not found" ) logger.info(f"Verifying package integrity: {package_name} (thorough={thorough})") try: cmd = ["pacman", "-Qkk" if thorough else "-Qk", package_name] exit_code, stdout, stderr = await run_command( cmd, timeout=30, check=False ) if exit_code != 0 and "was not found" in stderr: return create_error_response( "NotFound", f"Package not installed: {package_name}" ) # Parse verification output issues = [] for line in stdout.strip().split('\n'): if "warning" in line.lower() or "missing" in line.lower(): issues.append(line.strip()) logger.info(f"Found {len(issues)} issues for {package_name}") return { "package": package_name, "thorough": thorough, "issues_found": len(issues), "issues": issues, "all_ok": len(issues) == 0 } except Exception as e: logger.error(f"Package verification failed: {e}") return create_error_response( "CommandError", f"Failed to verify package: {str(e)}" ) - Tool registration with input schema defining package_name (required string) and thorough (optional boolean) parameters.
Tool( name="verify_package_integrity", description="[MAINTENANCE] Verify the integrity of installed package files. Detects modified, missing, or corrupted files. Only works on Arch Linux. When to use: After system crash or disk errors, verify 'linux' package files match expected checksums.", inputSchema={ "type": "object", "properties": { "package_name": { "type": "string", "description": "Name of the package to verify" }, "thorough": { "type": "boolean", "description": "Perform thorough check including file attributes. Default: false", "default": False } }, "required": ["package_name"] }, annotations=ToolAnnotations(readOnlyHint=True) ), - src/arch_ops_server/server.py:1177-1184 (registration)Tool dispatcher in call_tool() that routes 'verify_package_integrity' requests to the handler, with Arch Linux platform check.
elif name == "verify_package_integrity": if not IS_ARCH: return [TextContent(type="text", text=create_platform_error_message("verify_package_integrity"))] package_name = arguments["package_name"] thorough = arguments.get("thorough", False) result = await verify_package_integrity(package_name, thorough) return [TextContent(type="text", text=json.dumps(result, indent=2))] - src/arch_ops_server/pacman.py:1-110 (helper)Imports helper utilities from .utils including IS_ARCH, run_command, create_error_response, and check_command_exists used by the handler.
# SPDX-License-Identifier: GPL-3.0-only OR MIT """ Pacman/Official Repository interface module. Provides package info and update checks with hybrid local/remote approach. """ import logging import re from pathlib import Path from typing import Dict, Any, List, Optional, Union import httpx from .utils import ( IS_ARCH, run_command, create_error_response, check_command_exists ) logger = logging.getLogger(__name__) # Arch Linux package API ARCH_PACKAGES_API = "https://archlinux.org/packages/search/json/" # HTTP client settings DEFAULT_TIMEOUT = 10.0 async def get_official_package_info(package_name: str) -> Dict[str, Any]: """ Get information about an official repository package. Uses hybrid approach: - If on Arch Linux: Execute `pacman -Si` for local database query - Otherwise: Query archlinux.org API Args: package_name: Package name Returns: Dict with package information """ logger.info(f"Fetching info for official package: {package_name}") # Try local pacman first if on Arch if IS_ARCH and check_command_exists("pacman"): info = await _get_package_info_local(package_name) if info is not None: return info logger.warning(f"Local pacman query failed for {package_name}, trying remote API") # Fallback to remote API return await _get_package_info_remote(package_name) async def _get_package_info_local(package_name: str) -> Optional[Dict[str, Any]]: """ Query package info using local pacman command. Args: package_name: Package name Returns: Package info dict or None if failed """ try: exit_code, stdout, stderr = await run_command( ["pacman", "-Si", package_name], timeout=5, check=False ) if exit_code != 0: logger.debug(f"pacman -Si failed for {package_name}") return None # Parse pacman output info = _parse_pacman_output(stdout) if info: info["source"] = "local" logger.info(f"Successfully fetched {package_name} info locally") return info return None except Exception as e: logger.warning(f"Local pacman query failed: {e}") return None async def _get_package_info_remote(package_name: str) -> Dict[str, Any]: """ Query package info using archlinux.org API. Args: package_name: Package name Returns: Package info dict or error response """ params = { "name": package_name, "exact": "on" # Exact match only } try: async with httpx.AsyncClient(timeout=DEFAULT_TIMEOUT) as client: response = await client.get(ARCH_PACKAGES_API, params=params) response.raise_for_status() - Tool metadata definition: category=maintenance, platform=arch, permission=read, related_tools include query_package_history and query_file_ownership.
"verify_package_integrity": ToolMetadata( name="verify_package_integrity", category="maintenance", platform="arch", permission="read", workflow="verify", related_tools=["query_package_history", "query_file_ownership"], prerequisite_tools=[] ),