Closed bstaletic closed 10 months ago
As for the test, I have written this to prove that it works:
def test_removal_bootloader_symlink(self) -> None:
td = Path('/boot')
write_bzImage(td / 'kernel-0.0.0-suffix', b'kernel with a symlink')
write_bzImage(td / 'kernel-5.4.3-suffix', b'just a kernel')
Path( td / 'symlink_to_old' ).symlink_to( td / 'kernel-0.0.0-suffix' )
kernels = [
Kernel('0.0.0-suffix'),
Kernel('5.4.3-suffix')
]
kernels[0].all_files = [ KernelImage( td / 'kernel-0.0.0-suffix' ) ]
kernels[1].all_files = [ KernelImage( td / 'kernel-5.4.3-suffix' ) ]
class MockBootloader(Bootloader):
name = 'mock'
def __call__(self) -> typing.Iterable[str]:
yield str(td / 'symlink_to_old')
self.assertEqual(
get_removal_list(kernels,
sorter=VersionSort(),
limit=None,
destructive=False,
bootloader=MockBootloader()),
{kernels[1]: ['not referenced by bootloader (mock)'] })
However, since get_removal_list()
uses regex that hard-codes the /boot
part, this test writes to /boot
which is far from ideal. Any suggestions?
Thanks for taking a look. Okay, but I am afraid I do not know any other way to resolve a symlink and get a full path, which is all I am attempting to do.
I have tried os.readlink()
, but it only produces vmlinuz-6.4.9-test
, not /boot/vmlinuz-6.4.9-test
. pathlib.Path.resolve()
and pathlib.Path.readlink()
behave the same as os.readlink()
.
EDIT: Would the following be appropriate?
resolved_path = Path(fn).resolve()
fn = str(resolved_path.parent) + str(resolved_path)
My point is that we shouldn't be doing that on paths at all. From a quick look, we want to match kernels against bootloader entries, don't we? What the code really should do is use samefile()
to compare their equality.
I know it's a major change, so I can take a look at rewriting that part myself when I have some time.
Okay, now we are on the same page. I will close this pr and open a bug report. I can also take a closer look at what eclean-kernel is doing and how to achieve what you propose.
Thanks a lot!
This allows eclean-kernel to correctly identify the kernels used by the bootloader config in the following scenario:
image=/boot/vmlinuz
/boot/vmlinuz
is a symlink to/boot/vmlinuz-X.Y.Z-suffix
, which is the actual kernel.Before this commit, eclean-kernel -ap woulc complain that
and then list
vmlinuz-X.Y.Z-suffix
as one of the kernels to be removed.Note: This does affect my system, where the actual
lilo.conf
is something like this:and new kernels are installed through
installkernel
which comes frominstallkernel-gentoo
, which produces the following/boot/
: