diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 5ef0a17c2a..d887d07406 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -101,6 +101,19 @@ class zipimporter: self.prefix += path_sep + def _resolve_symlink(self, path): + try: + st = _bootstrap_external._path_stat(path) + if (st.st_mode & 0o170000) != 0o120000: # stat S_ISLNK + try: + path = self._files[path] + except KeyError: + raise OSError(0, '', path) + except (OSError, ValueError): + pass + return path + + # Check whether we can satisfy the import of the module named by # 'fullname', or whether it could be a portion of a namespace # package. Return self if we can load it, a string containing the @@ -174,7 +187,7 @@ class zipimporter: key = pathname[len(self.archive + path_sep):] try: - toc_entry = self._files[key] + toc_entry = self._files[self._resolve_symlink(key)] except KeyError: raise OSError(0, '', key) return _get_data(self.archive, toc_entry) @@ -210,7 +223,7 @@ class zipimporter: fullpath = f'{path}.py' try: - toc_entry = self._files[fullpath] + toc_entry = self._files[self._resolve_symlink(fullpath)] except KeyError: # we have the module, but no source return None