From 04bac6daa4fe81a9294fa6091600eb35145e74fe Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 2 Mar 2013 23:24:02 +0200 Subject: [PATCH] [PATCH] config: do not overwrite symlinks when saving config file --- 90/671e248da76012fb30265b64f19c66ae6c4f25 | 110 ++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 90/671e248da76012fb30265b64f19c66ae6c4f25 diff --git a/90/671e248da76012fb30265b64f19c66ae6c4f25 b/90/671e248da76012fb30265b64f19c66ae6c4f25 new file mode 100644 index 000000000..78b4f9fc4 --- /dev/null +++ b/90/671e248da76012fb30265b64f19c66ae6c4f25 @@ -0,0 +1,110 @@ +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 84C65431FBD + for ; Sat, 2 Mar 2013 13:24:07 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +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 TOT+pJQO-nEX for ; + Sat, 2 Mar 2013 13:24:06 -0800 (PST) +Received: from mail-la0-f45.google.com (mail-la0-f45.google.com + [209.85.215.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B0915431FAF + for ; Sat, 2 Mar 2013 13:24:05 -0800 (PST) +Received: by mail-la0-f45.google.com with SMTP id er20so3975056lab.18 + for ; Sat, 02 Mar 2013 13:24:04 -0800 (PST) +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 + :x-gm-message-state; + bh=zo9nARvV//OgxC31amhfUTTwZFB+68pdqmZgcSJGvKc=; + b=Wnk4ZSTRuN6PW592zQYX9kJGwFC9f/cGNPx2S8xL8Q5qFIKCA6pXzz2vYGJOuh0ZDm + 9iC/3Se7pBZJMSaTE/sRARYfw9z2ToPO55ldVQ9fmpqhgFf6s43aguAUnb6EW3tUvDQD + KDvxfB9q+9hxR+rOxOpZmjDZirCj3VX1LDJUlhAsAnBd7kfSGzCzz/GRE+dnsrbYOagb + RESlqKWOj/nMnOMcLceK2wW6nguE0bh71SXIGOsOR8wAAPcfNXvmuYiOvS5e6hXsBIpM + 14CHrcTHStE/Dmj71nd8FQvX53Zz0XVTCuJEm5tc18MGUqLmAAT1bBfMqa+wYkxujDQR + ca0w== +X-Received: by 10.152.46.17 with SMTP id r17mr13212033lam.47.1362259444006; + Sat, 02 Mar 2013 13:24:04 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id fm8sm5573848lbb.17.2013.03.02.13.24.02 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 02 Mar 2013 13:24:03 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] config: do not overwrite symlinks when saving config file +Date: Sat, 2 Mar 2013 23:24:02 +0200 +Message-Id: <1362259442-21014-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +X-Gm-Message-State: + ALoCoQn1xtFMYHep2UHyAaHTFIyBAh+oSU7ICxxba7OH+PP8Vk9Kjc6YIQvg+aYccgI88xwYTvOq +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:24:07 -0000 + +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); ++ ++ 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 + -- 2.26.2