fix: RecursionError caused by checking root dir incorrectly on Windows

This commit is contained in:
debugtalk
2020-01-03 18:16:05 +08:00
parent b93fae9475
commit 286dc3f7d5
2 changed files with 11 additions and 3 deletions

View File

@@ -9,6 +9,7 @@
**Fixed** **Fixed**
- fix #835: UnicodeDecodeError when loading json schema files - fix #835: UnicodeDecodeError when loading json schema files
- fix: RecursionError caused by checking root dir incorrectly on Windows
## 2.5.3 (2020-01-03) ## 2.5.3 (2020-01-03)

View File

@@ -8,7 +8,7 @@ project_working_directory = None
def locate_file(start_path, file_name): def locate_file(start_path, file_name):
""" locate filename and return absolute file path. """ locate filename and return absolute file path.
searching will be recursive upward until current working directory. searching will be recursive upward until current working directory or system root dir.
Args: Args:
file_name (str): target locate file name file_name (str): target locate file name
@@ -33,11 +33,18 @@ def locate_file(start_path, file_name):
return os.path.abspath(file_path) return os.path.abspath(file_path)
# current working directory # current working directory
if os.path.abspath(start_dir_path) in [os.getcwd(), os.path.abspath(os.sep)]: if os.path.abspath(start_dir_path) == os.getcwd():
raise exceptions.FileNotFound("{} not found in {}".format(file_name, start_path))
# system root dir
# Windows, e.g. 'E:\\'
# Linux/Darwin, '/'
parent_dir = os.path.dirname(start_dir_path)
if parent_dir == start_dir_path:
raise exceptions.FileNotFound("{} not found in {}".format(file_name, start_path)) raise exceptions.FileNotFound("{} not found in {}".format(file_name, start_path))
# locate recursive upward # locate recursive upward
return locate_file(os.path.dirname(start_dir_path), file_name) return locate_file(parent_dir, file_name)
def locate_debugtalk_py(start_path): def locate_debugtalk_py(start_path):