Просмотр исходного кода

[plugins] Handle `PermissionError` (#9229)

Authored by: syntaxsurge, pukkandan
Jade Laurence Empleo 1 год назад
Родитель
Сommit
9a8afadd17
1 измененных файлов с 7 добавлено и 4 удалено
  1. 7 4
      yt_dlp/plugins.py

+ 7 - 4
yt_dlp/plugins.py

@@ -86,11 +86,14 @@ class PluginFinder(importlib.abc.MetaPathFinder):
         parts = Path(*fullname.split('.'))
         for path in orderedSet(candidate_locations, lazy=True):
             candidate = path / parts
-            if candidate.is_dir():
-                yield candidate
-            elif path.suffix in ('.zip', '.egg', '.whl') and path.is_file():
-                if parts in dirs_in_zip(path):
+            try:
+                if candidate.is_dir():
                     yield candidate
+                elif path.suffix in ('.zip', '.egg', '.whl') and path.is_file():
+                    if parts in dirs_in_zip(path):
+                        yield candidate
+            except PermissionError as e:
+                write_string(f'Permission error while accessing modules in "{e.filename}"\n')
 
     def find_spec(self, fullname, path=None, target=None):
         if fullname not in self.packages: