unified-isos: Resolve symlinks

If the compose is configured to use symlinks for packages, the unified
ISO would include the symlinks which is useless.

Instead, let's check and replace any symlinks pointing outside of the
compose with the actual file.

JIRA: RHELCMP-13802
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 8ced384540)
This commit is contained in:
Lubomír Sedlář 2024-06-07 15:18:45 +02:00 committed by Stepan Oksanichenko
parent 6223baa2ba
commit 88b6d8ebf5
Signed by: soksanichenko
GPG Key ID: AB9983172AB1E45B

View File

@ -148,6 +148,13 @@ class UnifiedISO(object):
new_path = os.path.join(self.temp_dir, "trees", arch, old_relpath) new_path = os.path.join(self.temp_dir, "trees", arch, old_relpath)
makedirs(os.path.dirname(new_path)) makedirs(os.path.dirname(new_path))
# Resolve symlinks to external files. Symlinks within the
# provided `dir` are kept.
if os.path.islink(old_path):
real_path = os.readlink(old_path)
abspath = os.path.normpath(os.path.join(os.path.dirname(old_path), real_path))
if not abspath.startswith(dir):
old_path = real_path
try: try:
self.linker.link(old_path, new_path) self.linker.link(old_path, new_path)
except OSError as exc: except OSError as exc: