Enhance package deletion

If a corrupted Debian package is uploaded, apt-ostree fails to remove
it. This commit enhances the package deletion by removing the
component folders where the package resides.

Test-plan:
PASS: Remove a package using "apt-ostree repo remove \
      --feed <> --release bullseye --component <>"

Story: 2010676
Task: 51229

Change-Id: I37bb8ee125ef885b0c4ebf73a05e57c9a83ea50b
Signed-off-by: Lindley Vieira <lindley.vieira@windriver.com>
This commit is contained in:
Lindley Vieira 2024-10-18 12:05:34 -03:00
parent 22dc364545
commit 88f4e4f4e3

View File

@ -146,9 +146,41 @@ class Repo:
config = self.repo.joinpath("conf/distributions")
if utils.remove_component_from_config(config, component):
utils.run_command(
["reprepro", "-b", str(self.repo), "clearvanished"],
check=True)
dist_component = self.repo.joinpath(
f"dists/bullseye/{component}")
pool_component = self.repo.joinpath(f"pool/{component}")
try:
utils.run_command(
["rm", "-r", str(dist_component)],
check=True)
except Exception:
self.logging.info(f"Could not remove {dist_component},"
" skipping anyway\n")
try:
utils.run_command(
["rm", "-r", str(pool_component)],
check=True)
except Exception:
self.logging.info(f"Could not remove {pool_component},"
" skipping anyway\n")
try:
utils.run_command(
["reprepro", "-b", str(self.repo),
"--delete", "clearvanished"],
check=True)
except Exception:
self.logging.info("Could not run reprepro clearvanished,"
" skipping anyway\n")
try:
utils.run_command(
["reprepro", "-b", str(self.repo),
"deleteunreferenced"],
check=True)
except Exception:
self.logging.info("Could not run reprepro "
"deleteunreferenced, skipping anyway\n")
self.logging.info(f"Removed component {component}\n")
else:
self.logging.error(f"Failed to remove component {component}\n")