Skip to content

elbevalidate: treat hard-linked tar members as files - #484

Closed
koalo wants to merge 1 commit into
Linutronix:masterfrom
koalo:devel/koalo/fix-hardlinks
Closed

elbevalidate: treat hard-linked tar members as files#484
koalo wants to merge 1 commit into
Linutronix:masterfrom
koalo:devel/koalo/fix-hardlinks

Conversation

@koalo

@koalo koalo commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

TarPath.is_file() checked TarInfo.isfile(), which is only true for regular-file tar entries. For hard links, this is false even though we consider a hard linked file existent for every practical use.

Without this fix, checking for /usr/bin/unzip in the base-rootfs.tgz fails.

Comment thread test/test_elbevalidate.py Outdated
src_dir = tmp_path / 'src'
src_dir.mkdir()
src_dir.joinpath('a-original-file').write_text('Test content')
os.link(src_dir / 'a-original-file', src_dir / 'b-hardlinked-file')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pathlib, ie Path.hardlink_to().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread elbevalidate/path.py Outdated
info = self._info()
if info.islnk():
# For hard-links in tar files, isfile() is false
info = self.tar.getmember(info.linkname)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only need this for is_file() and not the other accessors, for example stat()?
It looks to me like we want to do this automatically in _info().

This now also has the issue, that the hardlink in a tar file can be broken, if the target does not exist.
But I think we can just wrap the KeyError from getmember() with a more descript error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TarPath.is_file() checked TarInfo.isfile(), which is only true for
regular-file tar entries. For hard links, this is false even though
we consider a hard linked file existent for every practical use.

Without this fix, checking for /usr/bin/unzip in the
base-rootfs.tgz fails.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
@koalo
koalo force-pushed the devel/koalo/fix-hardlinks branch from b9f2b08 to 74c1216 Compare September 1, 2026 08:36
@t-8ch

t-8ch commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Applied with minor changes, thanks!

@t-8ch t-8ch closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants