]> git.notmuchmail.org Git - notmuch/commitdiff
lib: add NOTMUCH_STATUS_PATH_ERROR
authorDavid Bremner <david@tethera.net>
Wed, 10 Jun 2015 05:58:44 +0000 (07:58 +0200)
committerDavid Bremner <david@tethera.net>
Fri, 12 Jun 2015 05:34:47 +0000 (07:34 +0200)
The difference with FILE_ERROR is that this is for things that are
wrong with the path before looking at the disk.

Add some 3 tests; two broken as a reminder to actually use this new
code.

lib/database.cc
lib/notmuch.h
test/T070-insert.sh
test/T560-lib-error.sh

index 78a24f7e0a43fe6fc9787c0d28ad4947d26280f4..e726f629dc89af2f1657125530d6889b9be02651 100644 (file)
@@ -342,6 +342,8 @@ notmuch_status_to_string (notmuch_status_t status)
        return "Unsupported operation";
     case NOTMUCH_STATUS_UPGRADE_REQUIRED:
        return "Operation requires a database upgrade";
        return "Unsupported operation";
     case NOTMUCH_STATUS_UPGRADE_REQUIRED:
        return "Operation requires a database upgrade";
+    case NOTMUCH_STATUS_PATH_ERROR:
+       return "Path supplied is illegal for this function";
     default:
     case NOTMUCH_STATUS_LAST_STATUS:
        return "Unknown error status value";
     default:
     case NOTMUCH_STATUS_LAST_STATUS:
        return "Unknown error status value";
index 20c4e0190c5cdc2f9e5d5464e9ab67192d424534..c8edc84dcbd702a3916b6204a6171d786b9956d2 100644 (file)
@@ -163,6 +163,11 @@ typedef enum _notmuch_status {
      * The operation requires a database upgrade.
      */
     NOTMUCH_STATUS_UPGRADE_REQUIRED,
      * The operation requires a database upgrade.
      */
     NOTMUCH_STATUS_UPGRADE_REQUIRED,
+    /**
+     * There is a problem with the proposed path, e.g. a relative path
+     * passed to a function expecting an absolute path.
+     */
+    NOTMUCH_STATUS_PATH_ERROR,
     /**
      * Not an actual status value. Just a way to find out how many
      * valid status values there are.
     /**
      * Not an actual status value. Just a way to find out how many
      * valid status values there are.
index 74f1955203f0f5cedcf0be633bcef440eeb5aa51..7e71c3b12afc1164faa9c5196f8d2296af56693b 100755 (executable)
@@ -188,7 +188,7 @@ notmuch config set new.tags $OLDCONFIG
 # DUPLICATE_MESSAGE_ID is not tested here, because it should actually pass.
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \
 # DUPLICATE_MESSAGE_ID is not tested here, because it should actually pass.
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \
-    READ_ONLY_DATABASE UPGRADE_REQUIRED; do
+    READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
 gen_insert_msg
 cat <<EOF > index-file-$code.gdb
 set breakpoint pending on
 gen_insert_msg
 cat <<EOF > index-file-$code.gdb
 set breakpoint pending on
index c99b17ed2fee141a43fb9faca006d3318f20d98e..9f5f7aefeea2e2c6fd44abc28c5e7ca29031840c 100755 (executable)
@@ -35,7 +35,8 @@ Error: Cannot open a database for a NULL path.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "Open nonexistent database"
+test_begin_subtest "Open relative path"
+test_subtest_known_broken
 test_C <<'EOF'
 #include <stdio.h>
 #include <notmuch.h>
 test_C <<'EOF'
 #include <stdio.h>
 #include <notmuch.h>
@@ -49,7 +50,44 @@ EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
 cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
-Error opening database at ./nonexistent/foo/.notmuch: No such file or directory
+Error: Database path must be absolute.
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Create database in relative path"
+test_subtest_known_broken
+test_C <<'EOF'
+#include <stdio.h>
+#include <notmuch.h>
+int main (int argc, char** argv)
+{
+    notmuch_database_t *db;
+    notmuch_status_t stat;
+    stat = notmuch_database_create ("./nonexistent/foo", &db);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+Error: Database path must be absolute.
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Open nonexistent database"
+test_C ${PWD}/nonexistent/foo <<'EOF'
+#include <stdio.h>
+#include <notmuch.h>
+int main (int argc, char** argv)
+{
+    notmuch_database_t *db;
+    notmuch_status_t stat;
+    stat = notmuch_database_open (argv[1], 0, 0);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 EOF
 test_expect_equal_file EXPECTED OUTPUT