Skip to content

Commit aeb39fa

Browse files
committed
rsync: use a more robust check for relative link than "startswith"
`startswith` is incorrect for paths in general, e.g. doesn't handle Windows extended-length paths and other such. The particular code here also wasn't careful about `/a/bc` not being relative to `/a/b`.
1 parent f90854b commit aeb39fa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

execnet/rsync.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ def _send_directory(self, path):
173173
self._send_directory_structure(p)
174174

175175
def _send_link_structure(self, path):
176-
linkpoint = os.readlink(path)
177176
basename = path[len(self._sourcedir) + 1 :]
178-
if linkpoint.startswith(self._sourcedir):
179-
self._send_link("linkbase", basename, linkpoint[len(self._sourcedir) + 1 :])
177+
linkpoint = os.readlink(path)
178+
try:
179+
relpath = os.path.relpath(linkpoint, self._sourcedir)
180+
except ValueError:
181+
relpath = None
182+
if relpath not in (None, os.curdir, os.pardir) and not relpath.startswith(
183+
os.pardir + os.sep
184+
):
185+
self._send_link("linkbase", basename, relpath)
180186
else:
181187
# relative or absolute link, just send it
182188
self._send_link("link", basename, linkpoint)

0 commit comments

Comments
 (0)