mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Improve is_subdir function before use in snapshot backups.
This commit is contained in:
parent
2e47d5b21e
commit
cda2e816e0
@ -544,17 +544,29 @@ class Helpers:
|
||||
|
||||
return mounts
|
||||
|
||||
def is_subdir(self, child_path, parent_path):
|
||||
def is_subdir(self, child_path: str, parent_path: str) -> bool:
|
||||
"""
|
||||
Checks if given child_path is a subdirectory of given parent_path. Returns True
|
||||
or False.
|
||||
|
||||
Args:
|
||||
child_path: Child path to check.
|
||||
parent_path: Possible parent path of child path.
|
||||
|
||||
Returns:
|
||||
True if child_path is a subdirectory of parent_path. Otherwise, False.
|
||||
|
||||
"""
|
||||
server_path = os.path.realpath(child_path)
|
||||
root_dir = os.path.realpath(parent_path)
|
||||
|
||||
if self.is_os_windows():
|
||||
try:
|
||||
relative = os.path.relpath(server_path, root_dir)
|
||||
except:
|
||||
except ValueError:
|
||||
# Windows will crash out if two paths are on different
|
||||
# Drives We can happily return false if this is the case.
|
||||
# Since two different drives will not be relative to eachother.
|
||||
# Since two different drives will not be relative to each-other.
|
||||
return False
|
||||
else:
|
||||
relative = os.path.relpath(server_path, root_dir)
|
||||
|
Loading…
Reference in New Issue
Block a user