From: Michael Kenneth S. David Date: Sat, 11 May 2024 07:10:59 +0000 (+0800) Subject: Fix renaming notes silently overwrites existing notes X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=0489949eafc03ae135ec73067643c7fc718ca2e6;p=flatnotes.git Fix renaming notes silently overwrites existing notes --- diff --git a/server/notes/file_system/file_system.py b/server/notes/file_system/file_system.py index 7c39855..386e0fc 100644 --- a/server/notes/file_system/file_system.py +++ b/server/notes/file_system/file_system.py @@ -80,6 +80,10 @@ class FileSystemNotes(BaseNotes): filepath = self._path_from_title(title) if data.new_title is not None: new_filepath = self._path_from_title(data.new_title) + if filepath != new_filepath and os.path.isfile(new_filepath): + raise FileExistsError( + f"Failed to rename. '{data.new_title}' already exists." + ) os.rename(filepath, new_filepath) title = data.new_title filepath = new_filepath