From 0fa8f18dbe096bde256872ecbd66ed7e872a199b Mon Sep 17 00:00:00 2001 From: Ayudh-M Date: Thu, 17 Apr 2025 13:16:15 +0200 Subject: [PATCH] new_post: log .meta path only when it exists (fix #3731) --- AUTHORS.txt | 1 + CHANGES.txt | 2 ++ nikola/plugins/command/new_post.py | 43 ++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 717e9d91fd..79213908b5 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -10,6 +10,7 @@ * `Aru Sahni `_ * `Arun Persaud `_ * `Aurelien Naldi `_ +* `Ayudh Haldar `_ * `Ben Mather `_ * `Bendik Knapstad `_ * `Boris Kaul `_ diff --git a/CHANGES.txt b/CHANGES.txt index f369a17f0c..a2502cb182 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -22,6 +22,8 @@ Bugfixes * Fix compatibility with watchdog 4 (Issue #3766) * ``nikola serve`` now works with non-root SITE_URL. * Stack traces meaningless for end users now more reliably suppressed (Issue #3838). +* Fix #3731: duplicate‑title check no longer logs a phantom “.meta created” path when the text or metadata file already exists in `nikola new_post`. + Other ----- diff --git a/nikola/plugins/command/new_post.py b/nikola/plugins/command/new_post.py index 0734ec8b84..61523a2f62 100644 --- a/nikola/plugins/command/new_post.py +++ b/nikola/plugins/command/new_post.py @@ -380,20 +380,41 @@ def _execute(self, options, args): txt_path = os.path.join(self.site.original_cwd, path) meta_path = os.path.splitext(txt_path)[0] + ".meta" - if (not onefile and os.path.isfile(meta_path)) or \ - os.path.isfile(txt_path): - - # Emit an event when a post exists - event = dict(path=txt_path) - if not onefile: # write metadata file - event['meta_path'] = meta_path - signal('existing_' + content_type).send(self, **event) + # ------------------------------------------------------------------ + # Previous implementation kept only for reference: + # if (not onefile and os.path.isfile(meta_path)) or os.path.isfile(txt_path): + # # Emit an event when a post exists + # # event = {"path": txt_path} + # # if not onefile: # write metadata file + # # event["meta_path"] = meta_path + # # signal("existing_" + content_type).send(self, **event) + # # + # # LOGGER.error("The title already exists!") + # # LOGGER.info("Existing {0}'s text is at: {1}".format(content_type, txt_path)) + # # if not onefile: + # # LOGGER.info("Existing {0}'s metadata is at: {1}".format(content_type, meta_path)) + # # return 8 + # ------------------------------------------------------------------ + + # Duplicate‑title check (reworked). Test the text and .meta files + # separately and only log paths that actually exist. + exists_txt = os.path.isfile(txt_path) + exists_meta = (not onefile) and os.path.isfile(meta_path) + + if exists_txt or exists_meta: + # Emit an “existing_post/page” signal with real paths + event = {"path": txt_path} + if exists_meta: + event["meta_path"] = meta_path + signal("existing_" + content_type).send(self, **event) LOGGER.error("The title already exists!") - LOGGER.info("Existing {0}'s text is at: {1}".format(content_type, txt_path)) - if not onefile: - LOGGER.info("Existing {0}'s metadata is at: {1}".format(content_type, meta_path)) + if exists_txt: + LOGGER.info("Existing %s's text is at: %s", content_type, txt_path) + if exists_meta: + LOGGER.info("Existing %s's metadata is at: %s", content_type, meta_path) return 8 + # ------------------------------------------------------------------ d_name = os.path.dirname(txt_path) utils.makedirs(d_name)