Skip to content

Commit f5cfa23

Browse files
committed
donate-cpu: do not abort unpacking on a hardlink to a missing member
1 parent 2f91952 commit f5cfa23

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
@@ -213,3 +213,16 @@ def test_unpack_package_link_redirected_later(tmpdir):
213213
if os.path.islink(inc_path):
214214
assert os.path.samefile(inc_path, os.path.join(temp_path, 'pkg', 'src', 'main.c'))
215215
assert os.listdir(outside_path) == ['secret.c']
216+
217+
def test_unpack_package_hardlink_missing_target(tmpdir):
218+
work_path = str(tmpdir)
219+
tgz = os.path.join(work_path, 'temp.tgz')
220+
with tarfile.open(tgz, 'w:gz') as tf:
221+
_add_tar_member(tf, 'pkg/main.c')
222+
# the target is neither on disk nor in the archive, so tarfile raises KeyError instead of OSError
223+
_add_tar_member(tf, 'pkg/copy.c', linkname='pkg/missing.c', linktype=tarfile.LNKTYPE)
224+
225+
temp_path, source_found = unpack_package(work_path, tgz)
226+
assert source_found
227+
assert os.path.isfile(os.path.join(temp_path, 'pkg', 'main.c'))
228+
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
@@ -444,7 +444,8 @@ def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None
444444
pass
445445
except AttributeError:
446446
pass
447-
except tarfile.TarError:
447+
except (tarfile.TarError, KeyError):
448+
# KeyError: hardlink to a member that is neither on disk nor in the archive
448449
pass
449450
removed = __remove_escaping_links(real_temp_path)
450451
extracted -= removed

0 commit comments

Comments
 (0)