mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
cli/dump: convert to new config framework
This conversion is trivial because the only configuration information accessed by dump is that stored in the database (in order to dump it). We do need to be careful to keep the write lock on the database to ensure dump consistency.
This commit is contained in:
parent
acc6331baa
commit
53f27aaf73
4 changed files with 54 additions and 8 deletions
|
@ -361,16 +361,11 @@ notmuch_database_dump (notmuch_database_t *notmuch,
|
|||
}
|
||||
|
||||
int
|
||||
notmuch_dump_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[])
|
||||
notmuch_dump_command (unused(notmuch_config_t *config), notmuch_database_t *notmuch , int argc, char *argv[])
|
||||
{
|
||||
notmuch_database_t *notmuch;
|
||||
const char *query_str = NULL;
|
||||
int ret;
|
||||
|
||||
if (notmuch_database_open (notmuch_config_get_database_path (config),
|
||||
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
notmuch_exit_if_unmatched_db_uuid (notmuch);
|
||||
|
||||
const char *output_file_name = NULL;
|
||||
|
|
|
@ -159,7 +159,7 @@ static command_t commands[] = {
|
|||
"Construct a reply template for a set of messages." },
|
||||
{ "tag", notmuch_tag_command, NOTMUCH_COMMAND_CONFIG_OPEN,
|
||||
"Add/remove tags for all messages matching the search terms." },
|
||||
{ "dump", notmuch_dump_command, NOTMUCH_COMMAND_CONFIG_OPEN,
|
||||
{ "dump", notmuch_dump_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
|
||||
"Create a plain-text dump of the tags for each message." },
|
||||
{ "restore", notmuch_restore_command, NOTMUCH_COMMAND_CONFIG_OPEN,
|
||||
"Restore the tags from the given dump file (see 'dump')." },
|
||||
|
|
|
@ -71,5 +71,55 @@ EOF
|
|||
restore_config
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
cat <<EOF > EXPECTED
|
||||
Before:
|
||||
#notmuch-dump batch-tag:3 tags
|
||||
|
||||
After:
|
||||
#notmuch-dump batch-tag:3 tags
|
||||
+attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
|
||||
+attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
|
||||
+inbox +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
|
||||
+inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu
|
||||
+inbox +signed +unread -- id:20091118002059.067214ed@hikari
|
||||
+inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu
|
||||
+inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag
|
||||
EOF
|
||||
|
||||
test_begin_subtest "dump with saved query from config file"
|
||||
backup_config
|
||||
query_name="test${RANDOM}"
|
||||
CONFIG_PATH=notmuch-config
|
||||
printf "Before:\n" > OUTPUT
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
printf "\nAfter:\n" >> OUTPUT
|
||||
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
restore_config
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
test_begin_subtest "dump with saved query from config file (xdg)"
|
||||
backup_config
|
||||
query_name="test${RANDOM}"
|
||||
xdg_config
|
||||
printf "Before:\n" > OUTPUT
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
printf "\nAfter:\n" >> OUTPUT
|
||||
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
restore_config
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
test_begin_subtest "dump with saved query from config file (xdg+profile)"
|
||||
backup_config
|
||||
query_name="test${RANDOM}"
|
||||
xdg_config work
|
||||
printf "Before:\n" > OUTPUT
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
printf "\nAfter:\n" >> OUTPUT
|
||||
printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
|
||||
notmuch dump --include=tags query:$query_name | sort >> OUTPUT
|
||||
restore_config
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
test_done
|
||||
|
|
|
@ -322,6 +322,7 @@ EOF
|
|||
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
backup_database
|
||||
test_begin_subtest 'roundtripping random message-ids and tags'
|
||||
|
||||
${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
|
||||
|
@ -338,7 +339,7 @@ test_begin_subtest 'roundtripping random message-ids and tags'
|
|||
sort > OUTPUT.$test_count
|
||||
|
||||
test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
|
||||
restore_database
|
||||
|
||||
test_done
|
||||
|
||||
# Note the database is "poisoned" for sup format at this point.
|
||||
|
|
Loading…
Reference in a new issue