From e472d4e0098463d7ebe18ad1c0dffd5328f8be06 Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Wed, 29 Jun 2022 22:22:06 +0200 Subject: [PATCH] First try --- jrnl/plugins/text_exporter.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index cfd4a8ec..2684f5aa 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -1,6 +1,7 @@ # Copyright (C) 2012-2022 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +import errno import os import re import unicodedata @@ -54,8 +55,20 @@ class TextExporter: """Exports a journal into individual files for each entry.""" for entry in journal.entries: full_path = os.path.join(path, cls.make_filename(entry)) - with open(full_path, "w", encoding="utf-8") as f: - f.write(cls.export_entry(entry)) + try: + with open(full_path, "w", encoding="utf-8") as f: + f.write(cls.export_entry(entry)) + except OSError as oserr: + if oserr.errno != errno.ENAMETOOLONG: + raise + else: + print("Oops OSError!") + # ONLY AVAILABLE ON UNIX, SO FIX + max_file_length = os.statvfs(path).f_namemax - len(cls.extension) - 12 + entry.title = str(entry.title)[:max_file_length] + full_path = os.path.join(path, cls.make_filename(entry)) + with open(full_path, "w", encoding="utf-8") as f: + f.write(cls.export_entry(entry)) print_msg( Message( MsgText.JournalExportedTo,