Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save santeri3700/bbac7ea46018411c7b2b629a04c68e26 to your computer and use it in GitHub Desktop.
Save santeri3700/bbac7ea46018411c7b2b629a04c68e26 to your computer and use it in GitHub Desktop.
A debugging script for checking Uyuni repodata Packages files for invalid Filename paths (uyuni#7788)
#!/usr/bin/python3
import os
# This script is published under public domain.
# Use at your own risk! No warranties provided!
# Author: Santeri Pikarinen (github.com/santeri3700)
# Get list of channel labels (subdirectories) under the repodata directory
# These directories and Packages files are genereated by Taskomatic DebPackageWriter
repodata_channel_labels = os.listdir("/var/cache/rhn/repodata/")
# print(f"Checking Packages files under the following channel labels: {repodata_channel_labels}\n")
# Loop through each channel label and open the Packages file for reading only
all_invalid_packages = []
for repodata_channel_label in repodata_channel_labels:
try:
with open("/var/cache/rhn/repodata/" + repodata_channel_label + "/Packages", "r") as packages_file:
invalid_packages = []
for line in packages_file:
if line.startswith("Filename: "):
# Example line: "Filename: mychannel-ubuntu2204_amd64/getPackage/mypackage_1.2.3-4.amd64-deb.deb"
# Strip the "Filename: " part without being length specific
filepath = line.replace("Filename: ", "").strip()
# Split the filepath per "/" into a list
filepath_parts = filepath.split("/")
# Get the channel label from the filepath
filepath_channel_label = filepath_parts[0]
# Get the package name from the filepath
filepath_package_name = filepath_parts[2]
# The package filename is invalid if the channel label is not the same as the repodata channel label
if repodata_channel_label != filepath_channel_label:
invalid_package = {
'real_channel': repodata_channel_label,
'wrong_channel': filepath_channel_label,
'package_name': filepath_package_name,
'filepath': filepath
}
invalid_packages.append(invalid_package)
all_invalid_packages.append(invalid_package)
if invalid_packages:
print(f"### {repodata_channel_label} ###")
print("# Downloading these packages will fail if not subscribed to the channel they are pointing to.")
for p in invalid_packages:
print(f"# - Package '{p['package_name']}' present in '{p['real_channel']}' but points to '{p['wrong_channel']}'")
print("#"*15+"\n")
except FileNotFoundError:
# This channel is probably not a DEB channel if the "Release" file doesn't exist
pass
if all_invalid_packages:
print(f"## There are total of {len(all_invalid_packages)} packages which are pointing to a wrong channel in the repodata/Packages file.\n")
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment