Merge branch 'release'

This commit is contained in:
David Bremner 2021-10-30 15:01:01 -03:00
commit e7bb7919a2
3 changed files with 131 additions and 10 deletions

View file

@ -433,6 +433,8 @@ notmuch_database_open_verbose (const char *path,
* @retval NOTMUCH_STATUS_NULL_POINTER: The given \a database
* argument is NULL.
*
* @retval NOTMUCH_STATUS_NO_CONFIG: No config file was found. Fatal.
*
* @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
*
* @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
@ -458,6 +460,9 @@ notmuch_database_open_with_config (const char *database_path,
*
* For description of arguments, @see notmuch_database_open_with_config
*
* For errors other then NO_DATABASE and NO_CONFIG, *database is set to
* NULL.
*
* @retval NOTMUCH_STATUS_SUCCESS: Successfully loaded configuration.
*
* @retval NOTMUCH_STATUS_NO_CONFIG: No config file was loaded. Not fatal.
@ -489,6 +494,9 @@ notmuch_database_load_config (const char *database_path,
*
* For description of arguments, @see notmuch_database_open_with_config
*
* In case of any failure, this function returns an error status and
* sets *database to NULL.
*
* @retval NOTMUCH_STATUS_SUCCESS: Successfully created the database.
*
* @retval NOTMUCH_STATUS_DATABASE_EXISTS: Database already exists, not created

View file

@ -396,8 +396,6 @@ _finish_open (notmuch_database_t *notmuch,
" has a newer database format version (%u) than supported by this\n"
" version of notmuch (%u).\n",
database_path, version, NOTMUCH_DATABASE_VERSION));
notmuch_database_destroy (notmuch);
notmuch = NULL;
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
@ -414,8 +412,6 @@ _finish_open (notmuch_database_t *notmuch,
" requires features (%s)\n"
" not supported by this version of notmuch.\n",
database_path, incompat_features));
notmuch_database_destroy (notmuch);
notmuch = NULL;
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
@ -489,8 +485,6 @@ _finish_open (notmuch_database_t *notmuch,
} catch (const Xapian::Error &error) {
IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
error.get_msg ().c_str ()));
notmuch_database_destroy (notmuch);
notmuch = NULL;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
DONE:
@ -559,10 +553,13 @@ notmuch_database_open_with_config (const char *database_path,
free (message);
}
if (status && notmuch) {
notmuch_database_destroy (notmuch);
notmuch = NULL;
}
if (database)
*database = notmuch;
else
talloc_free (notmuch);
if (notmuch)
notmuch->open = true;
@ -717,10 +714,16 @@ notmuch_database_create_with_config (const char *database_path,
else
free (message);
}
if (status && notmuch) {
notmuch_database_destroy (notmuch);
notmuch = NULL;
}
if (database)
*database = notmuch;
else
talloc_free (notmuch);
if (notmuch)
notmuch->open = true;
return status;
}
@ -868,6 +871,13 @@ notmuch_database_load_config (const char *database_path,
if (status_string)
*status_string = message;
if (status &&
status != NOTMUCH_STATUS_NO_DATABASE
&& status != NOTMUCH_STATUS_NO_CONFIG) {
notmuch_database_destroy (notmuch);
notmuch = NULL;
}
if (database)
*database = notmuch;

View file

@ -849,4 +849,107 @@ zzzafter afterval
EOF
test_expect_equal_file EXPECTED OUTPUT
cat <<EOF > c_head3
#include <notmuch-test.h>
int main (int argc, char **argv) {
notmuch_status_t stat;
notmuch_database_t *db = NULL;
EOF
cat <<EOF > c_tail3
printf("db == NULL: %d\n", db == NULL);
}
EOF
test_begin_subtest "open: database set to null on missing config"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
notmuch_status_t st = notmuch_database_open_with_config(argv[1],
NOTMUCH_DATABASE_MODE_READ_ONLY,
"/nonexistent", NULL, &db, NULL);
EOF
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "open: database set to null on missing config (env)"
old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
NOTMUCH_CONFIG="/nonexistent"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
notmuch_status_t st = notmuch_database_open_with_config(argv[1],
NOTMUCH_DATABASE_MODE_READ_ONLY,
NULL, NULL, &db, NULL);
EOF
NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "create: database set to null on missing config"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
notmuch_status_t st = notmuch_database_create_with_config(argv[1],argv[2], NULL, &db, NULL);
EOF
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "create: database set to null on missing config (env)"
old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
NOTMUCH_CONFIG="/nonexistent"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
notmuch_status_t st = notmuch_database_create_with_config(argv[1],
NULL, NULL, &db, NULL);
EOF
NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "load_config: database set non-null on missing config"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR} "/nonexistent"
notmuch_status_t st = notmuch_database_load_config(argv[1],argv[2], NULL, &db, NULL);
EOF
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 0
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "load_config: database non-null on missing config (env)"
old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
NOTMUCH_CONFIG="/nonexistent"
cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
notmuch_status_t st = notmuch_database_load_config(argv[1], NULL, NULL, &db, NULL);
EOF
NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 0
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "load_config: database set to NULL on fatal error"
cat c_head3 - c_tail3 <<'EOF' | test_C
notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL);
EOF
cat <<EOF> EXPECTED
== stdout ==
db == NULL: 1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
test_done