Skip to content

Commit

Permalink
eclean-pkg: deal with invalid binpkgs
Browse files Browse the repository at this point in the history
Changes required in portage -> gentoo/portage#1016

Bug: https://bugs.gentoo.org/900224
Signed-off-by: Siddhanth Rathod <xsiddhanthrathod@gmail.com>
Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
hyprsyd authored and thesamesam committed Aug 21, 2023
1 parent d936026 commit a16d0d4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
47 changes: 43 additions & 4 deletions pym/gentoolkit/eclean/cli.py
Expand Up @@ -13,15 +13,14 @@
__productname__ = "eclean"
__description__ = "A cleaning tool for Gentoo distfiles and binaries."


import os
import sys
import re
import time
import getopt

import portage
from portage.output import white, yellow, turquoise, green
from portage.output import white, yellow, turquoise, green, red

import gentoolkit.pprinter as pp
from gentoolkit.eclean.search import (
Expand All @@ -47,7 +46,7 @@ def printVersion():
print("Distributed under the terms of the GNU General Public License v2")


def printUsage(_error=None, help=None):
def printUsage(_error=None, help=None, unresolved_invalids=None):
"""Print help message. May also print partial help to stderr if an
error from {'options','actions'} is specified."""

Expand All @@ -63,10 +62,25 @@ def printUsage(_error=None, help=None):
"merged-distfiles-options",
"time",
"size",
"invalid_paths",
):
_error = None
if not _error and not help:
help = "all"
if _error == "invalid_paths":
print(
pp.error(
"eclean was not able to remove invalid binpkgs due to missing features in the currently installed portage"
),
file=out,
)
print(
pp.error("Please remove the following binpkgs manually:"),
file=out,
)
for invalid in unresolved_invalids:
print(pp.error(invalid), file=out)
return
if _error == "time":
print(pp.error("Wrong time specification"), file=out)
print(
Expand Down Expand Up @@ -399,6 +413,8 @@ def optionSwitch(option, opts, action=None):
options["ignore-failure"] = True
elif o in ("-u", "--unique-use"):
options["unique-use"] = True
elif o in ("-N", "--skip-invalids"):
options["clean-invalids"] = False
else:
return_code = False
# sanity check of --deep only options:
Expand Down Expand Up @@ -458,6 +474,7 @@ def optionSwitch(option, opts, action=None):
options["changed-deps"] = False
options["ignore-failure"] = False
options["unique-use"] = False
options["clean-invalids"] = True
# if called by a well-named symlink, set the action accordingly:
action = None
# temp print line to ensure it is the svn/branch code running, etc..
Expand Down Expand Up @@ -527,7 +544,7 @@ def doAction(action, options, exclude={}, output=None):
if not options["quiet"]:
output.einfo("Building file list for " + action + " cleaning...")
if action == "packages":
clean_me = findPackages(
clean_me, invalids = findPackages(
options,
exclude=exclude,
destructive=options["destructive"],
Expand Down Expand Up @@ -602,6 +619,28 @@ def doAction(action, options, exclude={}, output=None):
)
output.set_colors("deprecated")
output.list_pkgs(deprecated)
if invalids and options["clean-invalids"]:
if type(invalids) == list:
printUsage(_error="invalid_paths", unresolved_invalids=invalids)
sys.exit(1)
verb = "were"
if options["pretend"]:
verb = "would be"
if not options["quiet"]:
print()
print(
(
pp.emph(" The following ")
+ red("invalid")
+ pp.emph(" binpkgs were found")
)
)
output.set_colors("invalid")
output.list_pkgs(invalids)
clean_size = cleaner.clean_pkgs(invalids, pkgdir)
output.total("invalid", clean_size, len(invalids), verb, action)
else:
cleaner.clean_pkgs(invalids, pkgdir)


def main():
Expand Down
14 changes: 14 additions & 0 deletions pym/gentoolkit/eclean/output.py
Expand Up @@ -39,6 +39,9 @@ def set_colors(self, mode):
self.pkg_color = cpv # green
self.numbers = number # turquoise
self.brace = blue
if mode == "invalid":
self.pkg_color = red
self.numbers = teal
elif mode == "deprecated":
self.pkg_color = yellow
self.numbers = teal # darkgreen
Expand Down Expand Up @@ -169,6 +172,17 @@ def total(self, mode, size, num_files, verb, action):
)
print(" ===========")
print(self.prettySize(size, True, red), message)
elif mode == "invalid":
message = (
red(str(num_files))
+ " invalid binpkgs "
+ verb
+ " removed from the "
+ action
+ " directory"
)
print(" ===========")
print(self.prettySize(size, True, red), message)
elif mode == "deprecated":
message = (
"Total space from "
Expand Down
9 changes: 7 additions & 2 deletions pym/gentoolkit/eclean/search.py
Expand Up @@ -517,9 +517,10 @@ def findPackages(
pkgdir: str = None,
port_dbapi=portage.db[portage.root]["porttree"].dbapi,
var_dbapi=portage.db[portage.root]["vartree"].dbapi,
) -> dict[str, list[str]]:
) -> tuple[dict[str, list[str]], dict[str, list[str]]]:
"""Find obsolete binary packages.
@param invalid_paths:
@param options: dict of options determined at runtime
@type options: dict
@param exclude: exclusion dict (as defined in the exclude.parseExcludeFile class)
Expand Down Expand Up @@ -638,8 +639,12 @@ def findPackages(

binpkg_path = bin_dbapi.bintree.getname(cpv)
dead_binpkgs.setdefault(cpv, []).append(binpkg_path)
try:
invalid_paths = bin_dbapi.bintree.invalid_paths
except AttributeError:
invalid_paths = bin_dbapi.bintree.invalids

return dead_binpkgs
return dead_binpkgs, invalid_paths


# vim: set ts=4 sw=4 tw=79:

0 comments on commit a16d0d4

Please sign in to comment.