Skip to content

Commit 904ee65

Browse files
committed
donate-cpu: resolve symlink targets from the unresolved link location
1 parent 998d32a commit 904ee65

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎test/tools/donate_cpu_lib_test.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def test_unpack_package_duplicate_name(tmpdir):
111111
_add_tar_member(tf, 'pkg/sym.c', linkname=outside_file)
112112
_add_tar_member(tf, 'pkg/hard.c')
113113
_add_tar_member(tf, 'pkg/hard.c', linkname='../outside/target.c', linktype=tarfile.LNKTYPE)
114+
# a link inside temp followed by a same-named link that only looks inside when resolved through the first one
115+
_add_tar_member(tf, 'pkg/inc.h', linkname='a/b/c')
116+
_add_tar_member(tf, 'pkg/inc.h', linkname='../../outside')
114117

115118
temp_path, source_found = unpack_package(work_path, tgz)
116119
assert source_found
@@ -119,4 +122,7 @@ def test_unpack_package_duplicate_name(tmpdir):
119122
assert os.path.isfile(path)
120123
assert not os.path.islink(path)
121124
assert not os.path.samefile(path, outside_file)
125+
real_temp_path = os.path.realpath(temp_path)
126+
inc_path = os.path.realpath(os.path.join(temp_path, 'pkg', 'inc.h'))
127+
assert os.path.commonpath([real_temp_path, inc_path]) == real_temp_path
122128
assert os.listdir(outside_path) == ['target.c']

‎tools/donate_cpu_lib.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None
383383
member_path = os.path.realpath(os.path.join(temp_path, member.name))
384384
link_path = None
385385
if member.issym():
386-
link_path = os.path.realpath(os.path.join(os.path.dirname(member_path), member.linkname))
386+
# resolve from the directory the link is created in, not through an existing link with the same name
387+
link_parent = os.path.realpath(os.path.dirname(os.path.join(temp_path, member.name)))
388+
link_path = os.path.realpath(os.path.join(link_parent, member.linkname))
387389
elif member.islnk():
388390
link_path = os.path.realpath(os.path.join(temp_path, member.linkname))
389391
if not __is_inside_path(real_temp_path, member_path) or \

0 commit comments

Comments
 (0)