From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4CMPJEzhQGBGFgAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:31:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id MJfhH0zhQGC3MwAA1q6Kng (envelope-from ) for ; Thu, 04 Mar 2021 13:31:56 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 088C122BBD for ; Thu, 4 Mar 2021 14:31:56 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 738EE2756D; Thu, 4 Mar 2021 08:31:39 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 32D1926BF0 for ; Thu, 4 Mar 2021 08:31:33 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id E567E5FA96; Thu, 4 Mar 2021 08:31:32 -0500 (EST) Received: (nullmailer pid 4053588 invoked by uid 1000); Thu, 04 Mar 2021 13:31:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 22/22] CLI/new: use configuration variable for backup directory Date: Thu, 4 Mar 2021 09:31:25 -0400 Message-Id: <20210304133125.4050229-23-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304133125.4050229-1-david@tethera.net> References: <20210304133125.4050229-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 2EVH2VGS5GRD4DYIBD7UHKRQ6RZK7QHW X-Message-ID-Hash: 2EVH2VGS5GRD4DYIBD7UHKRQ6RZK7QHW X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1614864716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YRKYmqkrzLVbMOFWnFfGgbexaFCCkjpm85m32l3hbus=; b=l3xIrRYlP4+ZDc9js70Mk4imwYTAsGIdz+i26i/bMNNeWjeSgIo2aFJSkU4PgViNAI7kp3 1ftQfs3WjeKZuoTzvtENUFft9AxwKtvhXRoTBpUXspgqlNGBgIfybgGdxpet8AS+17m4LX OlceIRVWnd0OAli4bozmPHoQO88Tgj1n4LVIQZsktwm9T/XjQ/NvJjcjA/W3gYougL9w3T 8FV/Tz4NT9Mv+/BNtiDDCYopva7ukjt7Ni6EKiguwzsFSvTtmusRjN+mNGRqlk3tpkJNna B11tV/9s47BQFr7Lv+1WYUfGowjmRUjKCXL3QVj5OFyXS5HGXHxf5QUgfVHQFQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614864716; a=rsa-sha256; cv=none; b=MhxB0A+WH/SmGxTzBj/58YNhEQw2Q9EzFsgksMUBZskbVqX8CJgoBvR+/s1mtv2r8Pqufo 2TcDocU7ECTz1U1lj5v+5eHyX/Rl0HcAV8I5dpWvrrS/beKrKnT819LwXrT06vHt6qoLvI ehHzcXArrErG855BxctPsW3Y1aO7QUGGREjjt8iBXDlyizkPgA5cZGIFn9XWZD12dJOp8X mRkGw2kY1M2eXSJ13o+loUug+bT1vwSYKcB9TqkI0SoCajn0CnrTBs3Tx7d7q4OpNqNmS8 szne9EfWfAuPpk3hLXOANaX2H/gUbdSxD5OIKwmUY1Qr2zd22Zep4rwFJXktfA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.80 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 088C122BBD X-Spam-Score: -0.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: 01Fw7nfJjFzX The stat is dropped to avoid a race condition between stat and mkdir. This changes the default location for backups to make things tidier. Hopefully there is not user scripts relying on this location. --- notmuch-new.c | 18 ++++++------------ test/T055-path-config.sh | 15 +++++++++++++++ test/T530-upgrade.sh | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 63ac10a6..8a8ff69a 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1048,28 +1048,22 @@ _maybe_upgrade (notmuch_database_t *notmuch, add_files_state_t *state) { if (notmuch_database_needs_upgrade (notmuch)) { time_t now = time (NULL); struct tm *gm_time = gmtime (&now); - struct stat st; 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); const char *backup_name; - 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", - dot_notmuch_path ? dot_notmuch_path : state->db_path, + backup_dir, gm_time->tm_year + 1900, gm_time->tm_mon + 1, gm_time->tm_mday, diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh index e4812c82..d8828342 100755 --- a/test/T055-path-config.sh +++ b/test/T055-path-config.sh @@ -2,6 +2,8 @@ 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} @@ -13,6 +15,7 @@ restore_config () { unset CONFIG_PATH unset DATABASE_PATH unset NOTMUCH_PROFILE + unset XAPIAN_PATH cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG} } @@ -25,6 +28,7 @@ split_config () { notmuch config set database.path $dir notmuch config set database.mail_root $MAIL_DIR DATABASE_PATH=$dir + XAPIAN_PATH="$dir/xapian" } symlink_config () { @@ -34,6 +38,7 @@ symlink_config () { 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" unset DATABASE_PATH } @@ -56,6 +61,7 @@ xdg_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 } @@ -67,6 +73,7 @@ for config in traditional split XDG XDG+profile symlink; do case $config in traditional) backup_config + XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian" ;; split) split_config @@ -184,6 +191,14 @@ EOF 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." + restore_config done diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh index c599dacf..cce29f45 100755 --- a/test/T530-upgrade.sh +++ b/test/T530-upgrade.sh @@ -5,7 +5,7 @@ test_description='database upgrades' 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 -- 2.30.1