Skip to content

Commit 407f7f3

Browse files
committed
donate-cpu: do not abort unpacking on a hardlink to a missing member
1 parent a2f33a2 commit 407f7f3

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎test/tools/donate_cpu_lib_test.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,16 @@ def test_unpack_package_link_redirected_later(tmpdir):
154154
if os.path.islink(inc_path):
155155
assert os.path.samefile(inc_path, os.path.join(temp_path, 'pkg', 'src', 'main.c'))
156156
assert os.listdir(outside_path) == ['secret.c']
157+
158+
def test_unpack_package_hardlink_missing_target(tmpdir):
159+
work_path = str(tmpdir)
160+
tgz = os.path.join(work_path, 'temp.tgz')
161+
with tarfile.open(tgz, 'w:gz') as tf:
162+
_add_tar_member(tf, 'pkg/main.c')
163+
# the target is neither on disk nor in the archive, so tarfile raises KeyError instead of OSError
164+
_add_tar_member(tf, 'pkg/copy.c', linkname='pkg/missing.c', linktype=tarfile.LNKTYPE)
165+
166+
temp_path, source_found = unpack_package(work_path, tgz)
167+
assert source_found
168+
assert os.path.isfile(os.path.join(temp_path, 'pkg', 'main.c'))
169+
assert not os.path.lexists(os.path.join(temp_path, 'pkg', 'copy.c'))

‎tools/donate_cpu_lib.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None
443443
pass
444444
except AttributeError:
445445
pass
446-
except tarfile.TarError:
446+
except (tarfile.TarError, KeyError):
447+
# KeyError: hardlink to a member that is neither on disk nor in the archive
447448
pass
448449
removed = __remove_escaping_links(real_temp_path)
449450
extracted -= removed

0 commit comments

Comments
 (0)