file_manager: implement access check method

This method can be used by other components to check if Moonraker has
access to a particular file or folder.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-02-26 07:59:33 -05:00
parent a32bf4a47a
commit fd8bde7185
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 10 additions and 0 deletions

View File

@ -275,6 +275,16 @@ class FileManager:
file_path = os.path.join(root_dir, filename)
return os.path.exists(file_path)
def can_access_path(self, path: StrOrPath) -> bool:
if isinstance(path, str):
path = pathlib.Path(path)
path = path.expanduser().resolve()
for registered in self.file_paths.values():
reg_root_path = pathlib.Path(registered).resolve()
if reg_root_path in path.parents:
return True
return False
def upload_queue_enabled(self) -> bool:
return self.queue_gcodes