From: Tomi Ollila Date: Sat, 2 Mar 2013 21:58:12 +0000 (+0200) Subject: Re: [PATCH] config: do not overwrite symlinks when saving config file X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=3da56b2c875f71603c3581ed11261021fe718df5;p=notmuch-archives.git Re: [PATCH] config: do not overwrite symlinks when saving config file --- diff --git a/4c/8629314060bfdfcdca71bf426fdb0db744079c b/4c/8629314060bfdfcdca71bf426fdb0db744079c new file mode 100644 index 000000000..dd1c0e561 --- /dev/null +++ b/4c/8629314060bfdfcdca71bf426fdb0db744079c @@ -0,0 +1,111 @@ +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 96F7A431FBD + for ; Sat, 2 Mar 2013 13:58:28 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 zr2dkgnBZfuE for ; + Sat, 2 Mar 2013 13:58:24 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id BC36B431FAF + for ; Sat, 2 Mar 2013 13:58:24 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 7E7AC100093; + Sat, 2 Mar 2013 23:58:12 +0200 (EET) +From: Tomi Ollila +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH] config: do not overwrite symlinks when saving config file +In-Reply-To: <1362259442-21014-1-git-send-email-jani@nikula.org> +References: <1362259442-21014-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.15.2+48~g8dcc33e (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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: Sat, 02 Mar 2013 21:58:28 -0000 + +On Sat, Mar 02 2013, Jani Nikula wrote: + +> Use realpath on the config path before writing. If that fails, +> fallback to the previous behaviour. +> +> Previously 'notmuch setup' and 'notmuch config set' overwrote the +> config file even if it was a symbolic link. +> --- +> notmuch-config.c | 10 ++++++++-- +> 1 file changed, 8 insertions(+), 2 deletions(-) +> +> diff --git a/notmuch-config.c b/notmuch-config.c +> index b5c2066..1e7389f 100644 +> --- a/notmuch-config.c +> +++ b/notmuch-config.c +> @@ -461,7 +461,7 @@ int +> notmuch_config_save (notmuch_config_t *config) +> { +> size_t length; +> - char *data; +> + char *data, *filename; +> GError *error = NULL; +> +> data = g_key_file_to_data (config->key_file, &length, NULL); +> @@ -470,14 +470,20 @@ notmuch_config_save (notmuch_config_t *config) +> return 1; +> } +> +> - if (! g_file_set_contents (config->filename, data, length, &error)) { +> + /* Try not to overwrite symlinks. */ +> + filename = realpath (config->filename, NULL); + +The code looks good to me. But should we handle realpath returning NULL +differently. It should return NULL only on error. I suggest that +when realpath returns NULL, descriptive enough error message is returned +to the user so that the problem can be resolved and then tried again. + +Tomi + +> + +> + if (! g_file_set_contents (filename ? filename : config->filename, +> + data, length, &error)) { +> fprintf (stderr, "Error saving configuration to %s: %s\n", +> config->filename, error->message); +> g_error_free (error); +> + free (filename); +> g_free (data); +> return 1; +> } +> +> + free (filename); +> g_free (data); +> return 0; +> } +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch