Skip to content

new_post: log .meta path only when it exists (fix #3731) #3843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `Aru Sahni <https://github.com/arusahni>`_
* `Arun Persaud <https://github.com/arunpersaud>`_
* `Aurelien Naldi <https://github.com/aurelien-naldi>`_
* `Ayudh Haldar <https://github.com/Ayudh-M>`_
* `Ben Mather <https://github.com/bwhmather>`_
* `Bendik Knapstad <https://github.com/knapstad>`_
* `Boris Kaul <https://github.com/localvoid>`_
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
43 changes: 32 additions & 11 deletions nikola/plugins/command/new_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down