From dd3d3ffc82abd110b66a4e0af6ce2d990d702b7c Mon Sep 17 00:00:00 2001 From: juk0de Date: Sun, 10 Sep 2023 19:18:14 +0200 Subject: [PATCH] chat: added check for existing files when creating new filenames --- chatmastermind/chat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chatmastermind/chat.py b/chatmastermind/chat.py index ddabb56..7c4dd35 100644 --- a/chatmastermind/chat.py +++ b/chatmastermind/chat.py @@ -62,7 +62,10 @@ def make_file_path(dir_path: Path, Create a file_path for the given directory using the given file_suffix and ID generator function. """ - return dir_path / f"{next_fid():04d}{file_suffix}" + file_path = dir_path / f"{next_fid():04d}{file_suffix}" + while file_path.exists(): + file_path = dir_path / f"{next_fid():04d}{file_suffix}" + return file_path def write_dir(dir_path: Path,