fix: check read permission before entering a folder
This commit is contained in:
parent
51724a1aa6
commit
a144262f8c
1 changed files with 9 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ..items.AItems import AItem
|
from ..items.AItems import AItem
|
||||||
from ..items.Folder import Folder
|
from ..items.Folder import Folder
|
||||||
|
|
@ -44,24 +45,27 @@ class Navigator:
|
||||||
else:
|
else:
|
||||||
self._cursor.resete()
|
self._cursor.resete()
|
||||||
|
|
||||||
def _navigate_to(self, path: Path) -> None:
|
def _navigate_to(self, path: Path) -> bool:
|
||||||
|
if not os.access(path, os.R_OK | os.X_OK):
|
||||||
|
self._error = f"Permission denied: {path}"
|
||||||
|
return False
|
||||||
self._history.append(path)
|
self._history.append(path)
|
||||||
|
self._error = None
|
||||||
self._load()
|
self._load()
|
||||||
self._reset_cursor()
|
self._reset_cursor()
|
||||||
|
return True
|
||||||
|
|
||||||
def enter(self, item: AItem) -> bool:
|
def enter(self, item: AItem) -> bool:
|
||||||
if not item.is_navigable():
|
if not item.is_navigable():
|
||||||
return False
|
return False
|
||||||
path = item.point_to if isinstance(item, Symlink) else item.path
|
path = item.point_to if isinstance(item, Symlink) else item.path
|
||||||
self._navigate_to(path)
|
return self._navigate_to(path)
|
||||||
return True
|
|
||||||
|
|
||||||
def up(self) -> bool:
|
def up(self) -> bool:
|
||||||
parent = self._history[-1].parent
|
parent = self._history[-1].parent
|
||||||
if parent == self._history[-1]:
|
if parent == self._history[-1]:
|
||||||
return False
|
return False
|
||||||
self._navigate_to(parent)
|
return self._navigate_to(parent)
|
||||||
return True
|
|
||||||
|
|
||||||
def back(self) -> bool:
|
def back(self) -> bool:
|
||||||
if len(self._history) <= 1:
|
if len(self._history) <= 1:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue