]> git.cworth.org Git - notmuch/commitdiff
lib: add better diagnostics for over long filenames.
authorDavid Bremner <david@tethera.net>
Tue, 27 Dec 2022 17:08:47 +0000 (13:08 -0400)
committerDavid Bremner <david@tethera.net>
Mon, 20 Feb 2023 13:22:32 +0000 (09:22 -0400)
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.

lib/message.cc
lib/notmuch.h
notmuch-new.c
test/T050-new.sh

index 5ccca95a2a928d1e7fd3322a17871c7574cbfe35..1b1a071aa56e408597fd857787ecce742874f3ad 100644 (file)
@@ -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)
index 0b0540b13437f6161adbba741352ae9df0a2cdfd..ce375c042746f99532e75fd038bbd6ba9635bcf6 100644 (file)
@@ -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.
index 346e64697aaf02763a38eb09e93ef428348aae4a..4a53e3ebcc064cc531b8cb6255c422ff35938b30 100644 (file)
@@ -413,6 +413,10 @@ add_file (notmuch_database_t *notmuch, const char *filename,
     case NOTMUCH_STATUS_FILE_NOT_EMAIL:
        fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename);
        break;
+    case NOTMUCH_STATUS_PATH_ERROR:
+       fprintf (stderr, "Note: Ignoring non-indexable path: %s\n", filename);
+       (void) print_status_database ("add_file", notmuch, status);
+       break;
     case NOTMUCH_STATUS_FILE_ERROR:
        /* Someone renamed/removed the file between scandir and now. */
        state->vanished_files++;
index c4a51a0520767a78d8a677e98f69df90364a497b..09c2bfc65173ddd4641ed6648d17c227151b1e60 100755 (executable)
@@ -384,7 +384,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Long file names have reasonable diagnostics"
-test_subtest_known_broken
 printf -v name 'f%.0s' {1..234}
 generate_message "[filename]=$name"
 notmuch new 2>&1 | notmuch_dir_sanitize >OUTPUT