Fix unavailable paths.

Change catch potential exception because of unmounting of path during finding mount point.
Change add disabled message to webapi for freespace
This commit is contained in:
Prinz23 2023-03-13 01:51:01 +00:00 committed by JackDandy
parent 4dc131bc7d
commit 344fb19575
2 changed files with 23 additions and 8 deletions

View file

@ -1419,18 +1419,28 @@ def find_mount_point(path):
:param path: path to find the mount point
:return: mount point for path
"""
if not os.path.exists(path):
return path
org_path = path
path = os.path.realpath(os.path.abspath(path))
while not os.path.ismount(path):
path = os.path.dirname(path)
try:
while not os.path.ismount(path):
new_path = os.path.dirname(path)
if new_path == path:
# in case no mount point was found return original path
return org_path
path = new_path
except (BaseException, Exception):
return org_path
return path
def df():
# type: (...) -> Tuple[List[Tuple[AnyStr, AnyStr]], bool]
"""
Return disk free space at known parent locations
:return: string path, string value that is formatted size
:rtype: Tuple[List[Tuple[AnyStr, AnyStr]], bool]
"""
result = []
min_output = True
@ -1441,9 +1451,11 @@ def df():
if target and target not in targets:
min_output = False
targets += [target]
free = freespace(path)
free = freespace(target)
if None is not free:
result += [(target, sizeof_fmt(free).replace(' ', ''))]
else:
result += [(target, 'unavailable')]
return result, min_output

View file

@ -822,7 +822,7 @@ def _get_root_dirs(get_freespace=False):
default_dir = root_dirs[default_index]
if root_dirs and get_freespace:
if root_dirs and get_freespace and sickgear.DISPLAY_FREESPACE:
diskfree, _ = df()
for cur_root_dir in root_dirs:
@ -835,9 +835,12 @@ def _get_root_dirs(get_freespace=False):
new_entry = {'valid': valid, 'location': cur_root_dir, 'default': int(cur_root_dir is default_dir)}
if get_freespace:
# noinspection PyUnboundLocalVariable
new_entry.update({'free_space': next((space for disk, space in diskfree or []
if disk == find_mount_point(cur_root_dir)), '')})
if sickgear.DISPLAY_FREESPACE:
# noinspection PyUnboundLocalVariable
new_entry.update({'free_space': next((space for disk, space in diskfree or []
if disk == find_mount_point(cur_root_dir)), '')})
else:
new_entry.update({'free_space': 'Required setting "Display freespace" is not enabled'})
dir_list.append(new_entry)