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
|
|
@ -17,11 +17,13 @@ class DispatchLocal(Local):
|
|||
files: dict[str, str],
|
||||
installed: dict[str, str],
|
||||
simulate: str,
|
||||
sim_status: int = 0,
|
||||
) -> None:
|
||||
super().__init__('local')
|
||||
self.files = files
|
||||
self.installed = installed
|
||||
self.simulate = simulate
|
||||
self.sim_status = sim_status
|
||||
self.cmds: list[list[str]] = []
|
||||
|
||||
@override
|
||||
|
|
@ -45,7 +47,7 @@ class DispatchLocal(Local):
|
|||
status = 0 if name in self.installed else 1,
|
||||
)
|
||||
if '/usr/bin/apt-get' in cmd and '-s' in cmd:
|
||||
return Result(stdout = self.simulate.encode(), status = 0)
|
||||
return Result(stdout = self.simulate.encode(), status = self.sim_status)
|
||||
return Result(stdout = b'', status = 0)
|
||||
|
||||
def dpkg_args(cmd: list[str]) -> list[str]:
|
||||
|
|
@ -116,7 +118,7 @@ d = DebianDistro(cl, id = 'debian')
|
|||
asyncio.run(
|
||||
d._install_local_files(['/a/jw-base-run-1.0.0-42.deb'], False, install_deps = True)
|
||||
)
|
||||
pm_cmds = [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd]
|
||||
pm_cmds = [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd and '-s' not in cmd]
|
||||
assert len(pm_cmds) == 1
|
||||
args = pm_cmds[0][pm_cmds[0].index('/usr/bin/apt-get'):]
|
||||
assert 'install' in args
|
||||
|
|
@ -124,4 +126,61 @@ assert '--no-install-recommends' in args
|
|||
assert args[-1] == '/a/jw-base-run-1.0.0-42.deb'
|
||||
assert not [cmd for cmd in cl.cmds if '-i' in cmd]
|
||||
|
||||
# -- a name apt would replace with the repository's same-version
|
||||
# build (a version installed outside of apt) is dropped from the
|
||||
# install list, the remaining names are passed to apt-get
|
||||
cl = DispatchLocal(
|
||||
files = {},
|
||||
installed = {},
|
||||
simulate = (
|
||||
'The following packages will be upgraded:\n'
|
||||
'Inst jw-pkg-run [1.0.0-287] (1.0.0-287 rolling [amd64])\n'
|
||||
'Inst jw-python-run (1.0.0-61 rolling [amd64])\n'
|
||||
),
|
||||
)
|
||||
d = DebianDistro(cl, id = 'debian')
|
||||
asyncio.run(d._install(['jw-pkg-run', 'jw-python-run'], False))
|
||||
pm_cmds = [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd and '-s' not in cmd]
|
||||
assert len(pm_cmds) == 1
|
||||
args = pm_cmds[0][pm_cmds[0].index('/usr/bin/apt-get'):]
|
||||
assert 'jw-pkg-run' not in args
|
||||
assert 'jw-python-run' in args
|
||||
|
||||
# -- a real upgrade (different target version) is not dropped
|
||||
cl = DispatchLocal(
|
||||
files = {},
|
||||
installed = {},
|
||||
simulate = 'Inst jw-pkg-run [1.0.0-286] (1.0.0-287 rolling [amd64])\n',
|
||||
)
|
||||
d = DebianDistro(cl, id = 'debian')
|
||||
asyncio.run(d._install(['jw-pkg-run'], False))
|
||||
pm_cmds = [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd and '-s' not in cmd]
|
||||
assert len(pm_cmds) == 1
|
||||
args = pm_cmds[0][pm_cmds[0].index('/usr/bin/apt-get'):]
|
||||
assert 'jw-pkg-run' in args
|
||||
|
||||
# -- an arch-qualified Inst line matches the unqualified name
|
||||
cl = DispatchLocal(
|
||||
files = {},
|
||||
installed = {},
|
||||
simulate = 'Inst jw-pkg-run:amd64 [1.0.0-287] (1.0.0-287 rolling [amd64])\n',
|
||||
)
|
||||
d = DebianDistro(cl, id = 'debian')
|
||||
asyncio.run(d._install(['jw-pkg-run'], False))
|
||||
assert not [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd and '-s' not in cmd]
|
||||
|
||||
# -- a failed simulation passes all names through
|
||||
cl = DispatchLocal(
|
||||
files = {},
|
||||
installed = {},
|
||||
simulate = 'E: Unable to locate package jw-pkg-run',
|
||||
sim_status = 100,
|
||||
)
|
||||
d = DebianDistro(cl, id = 'debian')
|
||||
asyncio.run(d._install(['jw-pkg-run'], False))
|
||||
pm_cmds = [cmd for cmd in cl.cmds if '/usr/bin/apt-get' in cmd and '-s' not in cmd]
|
||||
assert len(pm_cmds) == 1
|
||||
args = pm_cmds[0][pm_cmds[0].index('/usr/bin/apt-get'):]
|
||||
assert 'jw-pkg-run' in args
|
||||
|
||||
print('All debian distro tests passed')
|
||||
|
|
|
|||
Loading…
Reference in a new issue