Skip to content

Commit 1ea1577

Browse files
committed
donate-cpu: resolve symlink targets from the unresolved link location
1 parent 6d6d7d6 commit 1ea1577

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
@@ -170,6 +170,9 @@ def test_unpack_package_duplicate_name(tmpdir):
170170
_add_tar_member(tf, 'pkg/sym.c', linkname=outside_file)
171171
_add_tar_member(tf, 'pkg/hard.c')
172172
_add_tar_member(tf, 'pkg/hard.c', linkname='../outside/target.c', linktype=tarfile.LNKTYPE)
173+
# a link inside temp followed by a same-named link that only looks inside when resolved through the first one
174+
_add_tar_member(tf, 'pkg/inc.h', linkname='a/b/c')
175+
_add_tar_member(tf, 'pkg/inc.h', linkname='../../outside')
173176

174177
temp_path, source_found = unpack_package(work_path, tgz)
175178
assert source_found
@@ -178,4 +181,7 @@ def test_unpack_package_duplicate_name(tmpdir):
178181
assert os.path.isfile(path)
179182
assert not os.path.islink(path)
180183
assert not os.path.samefile(path, outside_file)
184+
real_temp_path = os.path.realpath(temp_path)
185+
inc_path = os.path.realpath(os.path.join(temp_path, 'pkg', 'inc.h'))
186+
assert os.path.commonpath([real_temp_path, inc_path]) == real_temp_path
181187
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
@@ -384,7 +384,9 @@ def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None
384384
member_path = os.path.realpath(os.path.join(temp_path, member.name))
385385
link_path = None
386386
if member.issym():
387-
link_path = os.path.realpath(os.path.join(os.path.dirname(member_path), member.linkname))
387+
# resolve from the directory the link is created in, not through an existing link with the same name
388+
link_parent = os.path.realpath(os.path.dirname(os.path.join(temp_path, member.name)))
389+
link_path = os.path.realpath(os.path.join(link_parent, member.linkname))
388390
elif member.islnk():
389391
link_path = os.path.realpath(os.path.join(temp_path, member.linkname))
390392
if not __is_inside_path(real_temp_path, member_path) or \

0 commit comments

Comments
 (0)