aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-12-27 13:08:47 -0400
committerDavid Bremner <david@tethera.net>2023-02-20 09:22:32 -0400
commit09f2ad8e853375930c63bca847f623bc722b9cc0 (patch)
treec83851be016bd5ea542ac8b36f507b8068d5e83e /lib
parent4e6c6c8aac7f581448df525abd09b85c08358dd3 (diff)
lib: add better diagnostics for over long filenames.
Previously we just crashed with an internal error. With this change, the caller can handle it better. Update notmuch-new so that it doesn't crash with "unknown error code" because of this change.
Diffstat (limited to 'lib')
-rw-r--r--lib/message.cc16
-rw-r--r--lib/notmuch.h2
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 5ccca95a..1b1a071a 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -941,6 +941,7 @@ _notmuch_message_add_filename (notmuch_message_t *message,
{
const char *relative, *directory;
notmuch_status_t status;
+ notmuch_private_status_t private_status;
void *local = talloc_new (message);
char *direntry;
@@ -964,10 +965,17 @@ _notmuch_message_add_filename (notmuch_message_t *message,
/* New file-direntry allows navigating to this message with
* notmuch_directory_get_child_files() . */
- status = COERCE_STATUS (_notmuch_message_add_term (message, "file-direntry", direntry),
- "adding file-direntry term");
- if (status)
- return status;
+ private_status = _notmuch_message_add_term (message, "file-direntry", direntry);
+ switch (private_status) {
+ case NOTMUCH_PRIVATE_STATUS_SUCCESS:
+ break;
+ case NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG:
+ _notmuch_database_log (message->notmuch, "filename too long for file-direntry term: %s\n",
+ filename);
+ return NOTMUCH_STATUS_PATH_ERROR;
+ default:
+ return COERCE_STATUS (private_status, "adding file-direntry term");
+ }
status = _notmuch_message_add_folder_terms (message, directory);
if (status)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 0b0540b1..ce375c04 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -293,6 +293,8 @@ typedef struct _notmuch_indexopts notmuch_indexopts_t;
*
* NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
*
+ * NOTMUCH_STATUS_PATH_ERROR: filename is too long
+ *
* NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the
* database file (such as permission denied, or file not found,
* etc.), or the database already exists.