mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-13 14:43:03 +00:00
feat: catch errors when writing a file where a directory exists
This error sometimes happens when developing new plugins.
This commit is contained in:
parent
0a670d7ead
commit
b8394471ec
@ -43,6 +43,18 @@ def ensure_file_directory_exists(path: str) -> None:
|
||||
Create file's base directory if it does not exist.
|
||||
"""
|
||||
directory = os.path.dirname(path)
|
||||
if os.path.isfile(directory):
|
||||
raise exceptions.TutorError(
|
||||
"Attempting to create a directory, but a file with the same name already exists: {}".format(
|
||||
directory
|
||||
)
|
||||
)
|
||||
if os.path.isdir(path):
|
||||
raise exceptions.TutorError(
|
||||
"Attempting to write to a file, but a directory with the same name already exists: {}".format(
|
||||
directory
|
||||
)
|
||||
)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user