- commit
- 242a3b38960a57eebaa935b2e7a85001b6c60d2b
- parent
- 1ba49be2c6dc7775cf5f1b2c1be3241eecd34dfd
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-05-16 06:29
handle file system errors (e.g. PermissionError)
Diffstat
| M | cplay.py | 30 | +++++++++++++++++++----------- |
1 files changed, 19 insertions, 11 deletions
diff --git a/cplay.py b/cplay.py
@@ -129,14 +129,17 @@ def get_ext(path): 129 129 130 130 131 131 def listdir(path):132 -1 with os.scandir(path) as it:133 -1 for entry in sorted(it, key=lambda e: e.name):134 -1 if entry.name[0] != '.':135 -1 yield (136 -1 entry.path,137 -1 get_ext(entry.name),138 -1 entry.is_dir(follow_symlinks=False),139 -1 )-1 132 try: -1 133 with os.scandir(path) as it: -1 134 for entry in sorted(it, key=lambda e: e.name): -1 135 if entry.name[0] != '.': -1 136 yield ( -1 137 entry.path, -1 138 get_ext(entry.name), -1 139 entry.is_dir(follow_symlinks=False), -1 140 ) -1 141 except OSError: -1 142 pass 140 143 141 144 142 145 class Player: @@ -406,7 +409,7 @@ class Filelist(List): 406 409 super().__init__() 407 410 self.path = None 408 411 self.rsearch_str = ''409 -1 self.set_path(os.getcwd())-1 412 self.set_path(os.getcwd(), fail_silently=False) 410 413 411 414 def get_title(self): 412 415 title = f'Filelist: {self.path.rstrip("/")}/' @@ -421,10 +424,15 @@ class Filelist(List): 421 424 s += '/' 422 425 return s 423 426424 -1 def set_path(self, path, *, prev=None, refresh=False):-1 427 def set_path(self, path, *, prev=None, refresh=False, fail_silently=True): 425 428 if path != self.path: -1 429 try: -1 430 os.chdir(path) -1 431 except Exception: -1 432 if fail_silently: -1 433 return -1 434 raise 426 435 self.path = path427 -1 os.chdir(path)428 436 relpath.cache_clear() 429 437 self.search_cache = [] 430 438 elif refresh: