mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
lib: add NOTMUCH_STATUS_CLOSED_DATABASE, use in _n_d_ensure_writable
In order for a database to actually be writeable, it must be the case that it is open, not just the correct type of Xapian object. By explicitely checking, we are able to provide better error reporting, in particular for the previously broken test in T566-lib-message.
This commit is contained in:
parent
7e654e2a45
commit
3f27cce71f
7 changed files with 26 additions and 34 deletions
|
@ -55,6 +55,7 @@ ffibuilder.cdef(
|
||||||
NOTMUCH_STATUS_DATABASE_EXISTS,
|
NOTMUCH_STATUS_DATABASE_EXISTS,
|
||||||
NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
|
NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
|
||||||
NOTMUCH_STATUS_NO_MAIL_ROOT,
|
NOTMUCH_STATUS_NO_MAIL_ROOT,
|
||||||
|
NOTMUCH_STATUS_CLOSED_DATABASE,
|
||||||
NOTMUCH_STATUS_LAST_STATUS
|
NOTMUCH_STATUS_LAST_STATUS
|
||||||
} notmuch_status_t;
|
} notmuch_status_t;
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -476,6 +476,11 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
|
||||||
return NOTMUCH_STATUS_READ_ONLY_DATABASE;
|
return NOTMUCH_STATUS_READ_ONLY_DATABASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! notmuch->open) {
|
||||||
|
_notmuch_database_log (notmuch, "Cannot write to a closed database.\n");
|
||||||
|
return NOTMUCH_STATUS_CLOSED_DATABASE;
|
||||||
|
}
|
||||||
|
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return NOTMUCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,9 +857,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
notmuch_query_t *query = NULL;
|
notmuch_query_t *query = NULL;
|
||||||
unsigned int count = 0, total = 0;
|
unsigned int count = 0, total = 0;
|
||||||
|
|
||||||
status = _notmuch_database_ensure_writable (notmuch);
|
if (_notmuch_database_mode (notmuch) != NOTMUCH_DATABASE_MODE_READ_WRITE)
|
||||||
if (status)
|
return NOTMUCH_STATUS_READ_ONLY_DATABASE;
|
||||||
return status;
|
|
||||||
|
|
||||||
db = notmuch->writable_xapian_db;
|
db = notmuch->writable_xapian_db;
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,7 @@ typedef enum {
|
||||||
NOTMUCH_PRIVATE_STATUS_DATABASE_EXISTS = NOTMUCH_STATUS_DATABASE_EXISTS,
|
NOTMUCH_PRIVATE_STATUS_DATABASE_EXISTS = NOTMUCH_STATUS_DATABASE_EXISTS,
|
||||||
NOTMUCH_PRIVATE_STATUS_NO_MAIL_ROOT = NOTMUCH_STATUS_NO_MAIL_ROOT,
|
NOTMUCH_PRIVATE_STATUS_NO_MAIL_ROOT = NOTMUCH_STATUS_NO_MAIL_ROOT,
|
||||||
NOTMUCH_PRIVATE_STATUS_BAD_QUERY_SYNTAX = NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
|
NOTMUCH_PRIVATE_STATUS_BAD_QUERY_SYNTAX = NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
|
||||||
|
NOTMUCH_PRIVATE_STATUS_CLOSED_DATABASE = NOTMUCH_STATUS_CLOSED_DATABASE,
|
||||||
|
|
||||||
/* Then add our own private values. */
|
/* Then add our own private values. */
|
||||||
NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG = NOTMUCH_STATUS_LAST_STATUS,
|
NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG = NOTMUCH_STATUS_LAST_STATUS,
|
||||||
|
|
|
@ -228,6 +228,10 @@ typedef enum {
|
||||||
* No mail root could be deduced from parameters and environment
|
* No mail root could be deduced from parameters and environment
|
||||||
*/
|
*/
|
||||||
NOTMUCH_STATUS_NO_MAIL_ROOT,
|
NOTMUCH_STATUS_NO_MAIL_ROOT,
|
||||||
|
/**
|
||||||
|
* Database is not fully opened, or has been closed
|
||||||
|
*/
|
||||||
|
NOTMUCH_STATUS_CLOSED_DATABASE,
|
||||||
/**
|
/**
|
||||||
* Not an actual status value. Just a way to find out how many
|
* Not an actual status value. Just a way to find out how many
|
||||||
* valid status values there are.
|
* valid status values there are.
|
||||||
|
|
|
@ -243,14 +243,14 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
const char *path = talloc_asprintf(db, "%s/01:2,", argv[1]);
|
const char *path = talloc_asprintf(db, "%s/01:2,", argv[1]);
|
||||||
EXPECT0(notmuch_database_close (db));
|
EXPECT0(notmuch_database_close (db));
|
||||||
stat = notmuch_database_index_file (db, path, NULL, &msg);
|
stat = notmuch_database_index_file (db, path, NULL, &msg);
|
||||||
printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf ("%d\n", stat == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
1
|
1
|
||||||
== stderr ==
|
== stderr ==
|
||||||
A Xapian exception occurred finding message: Database has been closed.
|
Cannot write to a closed database.
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
@ -358,14 +358,14 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
EXPECT0(notmuch_database_close (db));
|
EXPECT0(notmuch_database_close (db));
|
||||||
stat = notmuch_database_set_config (db, "foo", "bar");
|
stat = notmuch_database_set_config (db, "foo", "bar");
|
||||||
printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf("%d\n", stat == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
1
|
1
|
||||||
== stderr ==
|
== stderr ==
|
||||||
Error: A Xapian exception occurred setting metadata: Database has been closed
|
Cannot write to a closed database.
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
|
|
@ -79,14 +79,14 @@ test_begin_subtest "delete directory document for a closed db"
|
||||||
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
stat = notmuch_directory_delete (dir);
|
stat = notmuch_directory_delete (dir);
|
||||||
printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf ("%d\n", stat == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
1
|
1
|
||||||
== stderr ==
|
== stderr ==
|
||||||
A Xapian exception occurred deleting directory entry: Database has been closed.
|
Cannot write to a closed database.
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
restore_database
|
restore_database
|
||||||
|
@ -97,32 +97,14 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
time_t stamp = notmuch_directory_get_mtime (dir);
|
time_t stamp = notmuch_directory_get_mtime (dir);
|
||||||
stat = notmuch_directory_set_mtime (dir, stamp);
|
stat = notmuch_directory_set_mtime (dir, stamp);
|
||||||
printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf ("%d\n", stat == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
1
|
1
|
||||||
== stderr ==
|
== stderr ==
|
||||||
A Xapian exception occurred setting directory mtime: Database has been closed.
|
Cannot write to a closed database.
|
||||||
EOF
|
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
|
||||||
restore_database
|
|
||||||
|
|
||||||
backup_database
|
|
||||||
test_begin_subtest "get/set mtime of directory for a closed db"
|
|
||||||
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
|
||||||
{
|
|
||||||
time_t stamp = notmuch_directory_get_mtime (dir);
|
|
||||||
stat = notmuch_directory_set_mtime (dir, stamp);
|
|
||||||
printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
cat <<EOF > EXPECTED
|
|
||||||
== stdout ==
|
|
||||||
1
|
|
||||||
== stderr ==
|
|
||||||
A Xapian exception occurred setting directory mtime: Database has been closed.
|
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
restore_database
|
restore_database
|
||||||
|
|
|
@ -231,7 +231,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
status = notmuch_message_add_tag (message, "boom");
|
status = notmuch_message_add_tag (message, "boom");
|
||||||
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
|
@ -247,7 +247,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
status = notmuch_message_remove_tag (message, "boom");
|
status = notmuch_message_remove_tag (message, "boom");
|
||||||
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
|
@ -427,7 +427,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
status = notmuch_message_remove_all_tags (message);
|
status = notmuch_message_remove_all_tags (message);
|
||||||
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
|
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
|
@ -443,7 +443,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
status = notmuch_message_freeze (message);
|
status = notmuch_message_freeze (message);
|
||||||
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
|
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
|
@ -459,7 +459,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
status = notmuch_message_thaw (message);
|
status = notmuch_message_thaw (message);
|
||||||
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
|
printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
|
|
Loading…
Reference in a new issue