The stat is essentially replaced by the mkdir for error detection
purposes. This changes the default location for backups to make
things tidier, even in non-split configurations. Hopefully there is
not too many user scripts relying on the previous location.
Because the default location may not exist, replace the use of stat
for error detection with a call to mkdir.
if (notmuch_database_needs_upgrade (notmuch)) {
time_t now = time (NULL);
struct tm *gm_time = gmtime (&now);
if (notmuch_database_needs_upgrade (notmuch)) {
time_t now = time (NULL);
struct tm *gm_time = gmtime (&now);
int err;
notmuch_status_t status;
int err;
notmuch_status_t status;
- char *dot_notmuch_path = talloc_asprintf (notmuch, "%s/%s", state->db_path, ".notmuch");
-
+ const char *backup_dir = notmuch_config_get (notmuch, NOTMUCH_CONFIG_BACKUP_DIR);
- err = stat (dot_notmuch_path, &st);
- if (err) {
- if (errno == ENOENT) {
- dot_notmuch_path = NULL;
- } else {
- fprintf (stderr, "Failed to stat %s: %s\n", dot_notmuch_path, strerror (errno));
- return EXIT_FAILURE;
- }
+ err = mkdir (backup_dir, 0755);
+ if (err && errno != EEXIST) {
+ fprintf (stderr, "Failed to create %s: %s\n", backup_dir, strerror (errno));
+ return EXIT_FAILURE;
}
/* since dump files are written atomically, the amount of
* harm from overwriting one within a second seems
* relatively small. */
backup_name = talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz",
}
/* since dump files are written atomically, the amount of
* harm from overwriting one within a second seems
* relatively small. */
backup_name = talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz",
- dot_notmuch_path ? dot_notmuch_path : state->db_path,
gm_time->tm_year + 1900,
gm_time->tm_mon + 1,
gm_time->tm_mday,
gm_time->tm_year + 1900,
gm_time->tm_mon + 1,
gm_time->tm_mday,
test_description='Configuration of mail-root and database path'
. $(dirname "$0")/test-lib.sh || exit 1
test_description='Configuration of mail-root and database path'
. $(dirname "$0")/test-lib.sh || exit 1
+test_require_external_prereq xapian-metdata
+
backup_config () {
local test_name=$(basename $0 .sh)
cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
backup_config () {
local test_name=$(basename $0 .sh)
cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
unset CONFIG_PATH
unset DATABASE_PATH
unset NOTMUCH_PROFILE
unset CONFIG_PATH
unset DATABASE_PATH
unset NOTMUCH_PROFILE
cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
}
cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
}
notmuch config set database.path $dir
notmuch config set database.mail_root $MAIL_DIR
DATABASE_PATH=$dir
notmuch config set database.path $dir
notmuch config set database.mail_root $MAIL_DIR
DATABASE_PATH=$dir
+ XAPIAN_PATH="$dir/xapian"
ln -s $MAIL_DIR $dir
notmuch config set database.path $dir
notmuch config set database.mail_root $MAIL_DIR
ln -s $MAIL_DIR $dir
notmuch config set database.path $dir
notmuch config set database.mail_root $MAIL_DIR
+ XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
mv ${NOTMUCH_CONFIG} $CONFIG_PATH
unset NOTMUCH_CONFIG
mv ${NOTMUCH_CONFIG} $CONFIG_PATH
unset NOTMUCH_CONFIG
+ XAPIAN_PATH="${DATABASE_PATH}/xapian"
notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
notmuch --config=${CONFIG_PATH} config set database.path
}
notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
notmuch --config=${CONFIG_PATH} config set database.path
}
case $config in
traditional)
backup_config
case $config in
traditional)
backup_config
+ XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
notmuch search --output=messages '*' | sort > OUTPUT
test_expect_equal_file EXPECTED OUTPUT
notmuch search --output=messages '*' | sort > OUTPUT
test_expect_equal_file EXPECTED OUTPUT
+ test_begin_subtest "upgrade backup ($config)"
+ features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
+ xapian-metadata set $XAPIAN_PATH features "$features"
+ output=$(notmuch new | grep Welcome)
+ test_expect_equal \
+ "$output" \
+ "Welcome to a new version of notmuch! Your database will now be upgraded."
+
test_require_external_prereq xapian-metadata
XAPIAN_PATH=$MAIL_DIR/.notmuch/xapian
test_require_external_prereq xapian-metadata
XAPIAN_PATH=$MAIL_DIR/.notmuch/xapian
-BACKUP_PATH=$MAIL_DIR/.notmuch
+BACKUP_PATH=$MAIL_DIR/.notmuch/backups
delete_feature () {
local key=$1
delete_feature () {
local key=$1