From: Jani Nikula Date: Sun, 5 May 2013 19:18:20 +0000 (+0300) Subject: [PATCH 2/2] cli: config: fix config file save when the file does not exist X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=accfacbfcfc3fb4d590226db81382971923fa6e4;p=notmuch-archives.git [PATCH 2/2] cli: config: fix config file save when the file does not exist --- diff --git a/04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8 b/04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8 new file mode 100644 index 000000000..de4e8f310 --- /dev/null +++ b/04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8 @@ -0,0 +1,135 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 52DF0431FC2 + for ; Sun, 5 May 2013 12:18:36 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Ibbu4LDRCJBp for ; + Sun, 5 May 2013 12:18:31 -0700 (PDT) +Received: from mail-la0-f54.google.com (mail-la0-f54.google.com + [209.85.215.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 77338431FAF + for ; Sun, 5 May 2013 12:18:31 -0700 (PDT) +Received: by mail-la0-f54.google.com with SMTP id fd20so2792525lab.13 + for ; Sun, 05 May 2013 12:18:29 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to + :references:in-reply-to:references:x-gm-message-state; + bh=5tNUn1jY6e6wO083LbMGb5kYv1FhDGZ2zIA44fcygpA=; + b=mMX4bpu0cEz9JIC/7w5VBN6PBmbQvaU1GQcVq/FTuXQLxPFSKyNNEPuKoopJubRvzA + 1BgN3GWHKPpf9fvbXCnOo4iOF0tGTdQ24DrfMh9mLMINOGSpuPOA+4ubKRKgBKdw4PyA + GWjLtvURnyjpVoWCjRpPGrHlyfyx4wN+Mkn9j+qeUdxITFGgFMIBtSqgECAcpuSNT4TD + LS8QXiK8lVEpzLwlUeq3lc5KJ3BQ+ygtOSSZzj/u2iZbzctB6IRLVZ8ppvtRbsVnRCRW + 7VA2gUZxtzTx5/xP0t6w/rmwWLlDcTiRxFY7iO07I+6hOX7Yqy9ECz4D9qbyo7+/8XD0 + XWsw== +X-Received: by 10.152.2.196 with SMTP id 4mr7039340law.4.1367781509834; + Sun, 05 May 2013 12:18:29 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi. + [88.195.118.211]) + by mx.google.com with ESMTPSA id 2sm3837120lay.5.2013.05.05.12.18.28 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 05 May 2013 12:18:29 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] cli: config: fix config file save when the file does not + exist +Date: Sun, 5 May 2013 22:18:20 +0300 +Message-Id: + <66bdb2255d3a5ec573ac2a935663e9f767610d36.1367781422.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: + <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org> +References: + <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org> +In-Reply-To: + <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org> +References: + <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org> +X-Gm-Message-State: + ALoCoQlYtu6/ccs0Sugw4PsV4PR99KP1soIemcIR6n4k/jof+3bQpuEISQYnEo8l7tEGvySBxvG3 +Cc: Tomi Ollila +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 05 May 2013 19:18:36 -0000 + +The use of realpath(3) in +commit 58ed67992d0ec1fa505026105218fa449f7980b0 +Author: Jani Nikula +Date: Sun Apr 7 20:15:03 2013 +0300 + + cli: config: do not overwrite symlinks when saving config file + +broke config file save when the file does not exist, which results in +'notmuch setup' always failing to create a new config file. + +Fix by checking ENOENT from realpath(3). +--- + notmuch-config.c | 17 +++++++++++++---- + test/setup | 1 - + 2 files changed, 13 insertions(+), 5 deletions(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index d9c2eb3..befe9b5 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -456,10 +456,19 @@ notmuch_config_save (notmuch_config_t *config) + /* Try not to overwrite symlinks. */ + filename = realpath (config->filename, NULL); + if (! filename) { +- fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename, +- strerror (errno)); +- g_free (data); +- return 1; ++ if (errno == ENOENT) { ++ filename = strdup (config->filename); ++ if (! filename) { ++ fprintf (stderr, "Out of memory.\n"); ++ g_free (data); ++ return 1; ++ } ++ } else { ++ fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename, ++ strerror (errno)); ++ g_free (data); ++ return 1; ++ } + } + + if (! g_file_set_contents (filename, data, length, &error)) { +diff --git a/test/setup b/test/setup +index 8cc5576..124ef1c 100755 +--- a/test/setup ++++ b/test/setup +@@ -4,7 +4,6 @@ test_description='"notmuch setup"' + . ./test-lib.sh + + test_begin_subtest "Create a new config interactively" +-test_subtest_known_broken + notmuch --config=new-notmuch-config > /dev/null <