lib.distros.debian.Distro._install(): Protect installed pkgs
apt 3.x distinguishes versions with the same version number by their control metadata, so a .deb installed with dpkg -i that differs from the repository's same-version package is regarded as a separate version, and apt-get install of the package name "upgrades" it to the repository version, replacing the installed package. If the installed package was built from the source code repo's master, this is effectively a downgrade and can break a CI run in currently unintended ways. This commit detects same-version packages in apt-get's install todo list by running apt-get -s install (simulate installation), parsing the output, and removing those packages from the command line of the subsequent, real install command. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c16bc81d67
commit
302d3fe791
1 changed files with 115 additions and 3 deletions
|
|
@ -42,6 +42,55 @@ class Distro(Base):
|
|||
kwargs.setdefault('ec', self.ctx)
|
||||
return await run_dpkg(*args, **kwargs)
|
||||
|
||||
# apt 3.x distinguishes versions with the same version number by
|
||||
# their control metadata, so a package installed outside of apt
|
||||
# that differs from the repository's same-version package is
|
||||
# regarded as a separate version, and apt-get <package-name>
|
||||
# would replace it with the repository version, which breaks CI.
|
||||
# This method identifies such names with agt_get -s install
|
||||
# (simulate) and drops them from the list, keeping the installed
|
||||
# version.
|
||||
async def __mask_installed(self, names: list[str], only_update: bool) -> list[str]:
|
||||
args = ['-s', 'install']
|
||||
if only_update:
|
||||
args.append('--only-upgrade')
|
||||
args.append('--no-install-recommends')
|
||||
args.extend(names)
|
||||
try:
|
||||
result = await self.apt_get(args, verbose = False, sudo = False)
|
||||
except Exception:
|
||||
return names
|
||||
if result.status != 0:
|
||||
return names
|
||||
replaced: dict[str, str] = {}
|
||||
for line in result.stdout_str.splitlines():
|
||||
parts = line.split()
|
||||
if len(parts) < 3 or parts[0] != 'Inst':
|
||||
continue
|
||||
name = parts[1].split(':', 1)[0]
|
||||
installed: str | None = None
|
||||
target: str | None = None
|
||||
for part in parts[2:]:
|
||||
if part.startswith('[') and part.endswith(']'):
|
||||
installed = part[1:-1]
|
||||
elif part.startswith('('):
|
||||
target = part[1:]
|
||||
break
|
||||
if installed is not None and installed == target:
|
||||
replaced[name] = installed
|
||||
ret: list[str] = []
|
||||
for name in names:
|
||||
if installed := replaced.get(name):
|
||||
log(
|
||||
NOTICE,
|
||||
f'keeping installed {name} {installed}: apt would '
|
||||
'replace it with the repository package of the same '
|
||||
'version',
|
||||
)
|
||||
continue
|
||||
ret.append(name)
|
||||
return ret
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
|
@ -80,11 +129,15 @@ class Distro(Base):
|
|||
|
||||
@override
|
||||
async def _install(self, names: Iterable[str], only_update: bool) -> None:
|
||||
names = list(names)
|
||||
keep = await self.__mask_installed(names, only_update)
|
||||
if not keep:
|
||||
return
|
||||
args = ['install']
|
||||
if only_update:
|
||||
args.append('--only-upgrade')
|
||||
args.append('--no-install-recommends')
|
||||
args.extend(names)
|
||||
args.extend(keep)
|
||||
await self.apt_get(args)
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Reference in a new issue