Skip to content
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
6 changes: 6 additions & 0 deletions jrnl/plugins/text_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def write_files(cls, journal: "Journal", path: str) -> str:
entry_is_written = False
while not entry_is_written:
full_path = os.path.join(path, cls.make_filename(entry))
if os.path.exists(full_path):
base, extension = os.path.splitext(full_path)
counter = 2
while os.path.exists(f"{base}_{counter}{extension}"):
counter += 1
full_path = f"{base}_{counter}{extension}"
try:
with open(full_path, "w", encoding="utf-8") as f:
f.write(cls.export_entry(entry))
Expand Down
13 changes: 13 additions & 0 deletions tests/bdd/features/format.feature
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,19 @@ Feature: Custom formats
When we run "jrnl --format markdown --file {cache_dir}"
Then the cache directory should contain 5 files
And we should get no error

Scenario: Export entries with identical dates and titles
Given we use the config "basic_onefile.yaml"
And we create a cache directory
When we run "jrnl 2020-10-20 01:00: same title"
When we run "jrnl 2020-10-20 02:00: same title"
When we run "jrnl --format text --file {cache_dir}"
Then the cache directory should contain the files
"""
2020-10-20_same-title.txt
2020-10-20_same-title_2.txt
"""
And we should get no error

Scenario: Export entries in text format with a title longer than max file name length.
Given we use the config "basic_onefile.yaml"
Expand Down