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 35BDF40DBFE for ; Tue, 16 Nov 2010 12:27:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=unavailable 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 M-cv0HjCr0BB for ; Tue, 16 Nov 2010 12:27:31 -0800 (PST) Received: from mail-vw0-f53.google.com (mail-vw0-f53.google.com [209.85.212.53]) by olra.theworths.org (Postfix) with ESMTP id 307F240DBFA for ; Tue, 16 Nov 2010 12:27:31 -0800 (PST) Received: by vws7 with SMTP id 7so658367vws.26 for ; Tue, 16 Nov 2010 12:27:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=7o/Ss+r3icQeFKRDTQ1w/AKW3QnXEOFxjPc4kZPqj5s=; b=ngouzv2Fkc3eqojmYoetb2DjDR/NrAk9Pejum9fjo40tJVhFjsx4z1nCE1SXV9CD+M 2iA2v8fF2hTJ+/TYJ8k4mf2lqYqBQr6lj6LmYVIDzph6/tzUGDg6XDKXkbg2DLP0gUaI ZWb5ho8yWhdcNWfPVWQ5+tZBiJFe5tBJN9Zj0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=GCqm4q+liH4aghzYHFOWES8l0JCauqp/tcngUpHdK/+p0paXQdr2HaN3X+c/vbBo0V cgHj+PFWkUcCiD78h0Kgs8ylAu0rKPgo8WhPbxRsE6ziFh6ugSg2LqpHK7VhW/X9s5+p hPhDkxiDF1l6d3ph/IFaejrR5DroM+OMXLrLA= Received: by 10.229.191.130 with SMTP id dm2mr6566897qcb.256.1289939247246; Tue, 16 Nov 2010 12:27:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.189.17 with HTTP; Tue, 16 Nov 2010 12:26:56 -0800 (PST) In-Reply-To: <87sjz1dr0j.fsf@yoom.home.cworth.org> References: <87sjz1dr0j.fsf@yoom.home.cworth.org> From: "Ciprian Dorin, Craciun" Date: Tue, 16 Nov 2010 22:26:56 +0200 Message-ID: Subject: Re: `notmuch setup` replaces `~/.notmuch-config` instead of truncating it To: Carl Worth Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: notmuch@notmuchmail.org 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: Tue, 16 Nov 2010 20:27:43 -0000 On Tue, Nov 16, 2010 at 21:09, Carl Worth wrote: > On Tue, 16 Nov 2010 15:33:30 +0200, "Ciprian Dorin, Craciun" wrote: >> =C2=A0 =C2=A0 So my question is: is this behaviour (of deleting the file= and >> creating a new one) deliberate? If not, could it be fixed (I could >> provide a patch) to just update the file in place? > > Daniel gave the perfect answer later in the thread. It is intentional to > replace the file with a new, complete version, (to avoid loss/corruption > of the file if "notmuch setup" is interrupted). But we should fix this > to replace the target of any symlinks. > > -Carl I understand now the reason for your file replacement choice. (I'll look over tomorrow to see if I can provide a patch on the line Daniel has described). But -- in general, and totally overlooking the "pseudo" atomic effect obtained from of POSIX file semantics -- doesn't this practice mislead some software (like backup systems, etc.) that would rely maybe on the inode number as part of the identity of the file? Moreover what if the user has set any ACL's or extended attributes on the file, wouldn't these be lost? (Wouldn't also SELinux be bothered?) So after browsing through the source code, I've found inside `notmuch-config.c`, inside the function `notmuch_config_save`, the call which actually overrides the file: `g_file_set_contents (config->filename, data, length, &error)`. Now searching for the documentation of this function, I've stumbled upon, from which I cite (I've never used glib before, so maybe the link is not the best one): http://library.gnome.org/devel/glib/unstable/glib-File-Utilities.ht= ml ~~~~ On Unix, if filename already exists hard links to filename will break. Also since the file is recreated, existing permissions, access control lists, metadata etc. may be lost. If filename is a symbolic link, the link itself will be replaced, not the linked file. ~~~~ So in the light of the above quoted "glitches", my question is: due to the small chance of a power loss happening right when we write such a small file, doesn't the inconvenience weight more than the (fairly remote probable) file loss? (I must admit I've lost once the `/etc/network/interfaces` file after an edit and immediately after a quick cold reboot, but it was my fault as I've not sync-ed the file system.) Ciprian. P.S.: I say "pseudo" atomic because only the rename is atomic, thus in order to override file `a` for the target file `b` which exists, we must execute two **non-atomic** operations as a whole, but each atomic in part, rename operations: make `b` -> `c`, and then rename `a` -> `b`. So there is actually a small time-frame when I can be left with two files (`a` and `c`), none of which is my config file `b`. (This can be solved when opening the config file by checking if there isn't any leftover `c` or `a` file, in which case I take the `a` file and complete the rename.)