From debbugs-submit-bounces@debbugs.gnu.org Sun May 19 21:10:26 2024 Received: (at submit) by debbugs.gnu.org; 20 May 2024 01:10:27 +0000 Received: from localhost ([127.0.0.1]:39007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8rXg-00012j-O1 for submit@debbugs.gnu.org; Sun, 19 May 2024 21:10:26 -0400 Received: from lists.gnu.org ([209.51.188.17]:51546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8rXe-00012d-HM for submit@debbugs.gnu.org; Sun, 19 May 2024 21:10:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8rVS-0007im-Lb for bug-gnu-emacs@gnu.org; Sun, 19 May 2024 21:08:02 -0400 Received: from joooj.vinc17.net ([2001:4b99:1:3:216:3eff:fe20:ac98]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8rVR-0007ij-2e for bug-gnu-emacs@gnu.org; Sun, 19 May 2024 21:08:02 -0400 Received: from smtp-qaa.vinc17.net (135.197.67.86.rev.sfr.net [86.67.197.135]) by joooj.vinc17.net (Postfix) with ESMTPSA id BFDF7323; Mon, 20 May 2024 03:07:48 +0200 (CEST) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 9243DCA00B5; Mon, 20 May 2024 03:07:48 +0200 (CEST) Date: Mon, 20 May 2024 03:07:48 +0200 From: Vincent Lefevre To: bug-gnu-emacs@gnu.org Subject: 29.3; When doing a backup, the file is missing during interactive questions Message-ID: <20240520010748.GB323381@qaa.vinc17.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.13+76 (1f3da810) vl-167818 (2024-04-20) Received-SPF: pass client-ip=2001:4b99:1:3:216:3eff:fe20:ac98; envelope-from=vincent@vinc17.net; helo=joooj.vinc17.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) When doing a backup, GNU Emacs renames the file (according to strace). Under some conditions, the file can be lost. I noticed that due to a bug in the combination between Emacs and gpg, where the "save" operation cannot be completed. To reproduce with "emacs -Q", do for a file that is not under version control (otherwise --eval="(setq vc-make-backup-files t)" is needed): 1. emacs -Q file.gpg 2. Modify the file. 3. Save with C-x C-s At this point, gpg gets interactive, with a question Untrusted key [...]. Use anyway? (y or n) and one can see that the file "file.gpg" has been renamed to "file.gpg~". And it may happen that the save operation will never be completed, e.g. because of a bug like https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1071372 (where gpg never terminates) or because Emacs may be killed before the user could complete the save operation. In short, the file may have silently disappeared. There is a backup, but the backups may be cleaned up before the user realizes the issue. Note: I put the backups in a specific directory with (defun find-backup-file-name (fn) (list (concat "~/.poub/" (file-name-nondirectory fn) "~"))) but I look at it only when I know I've done something wrong or if I get an error message about the save operation. Having a missing file during interactive questions is bad. Note: I'm using Debian's package emacs-gtk 1:29.3+1-3. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) From debbugs-submit-bounces@debbugs.gnu.org Mon May 20 07:31:28 2024 Received: (at 71074) by debbugs.gnu.org; 20 May 2024 11:31:28 +0000 Received: from localhost ([127.0.0.1]:42161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s91El-0003VZ-0O for submit@debbugs.gnu.org; Mon, 20 May 2024 07:31:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s91EU-0003P4-HO for 71074@debbugs.gnu.org; Mon, 20 May 2024 07:31:25 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s91EK-0003vE-3p; Mon, 20 May 2024 07:31:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=pF3K1dVqbr8SnoETDw64MZCn2HclUQyiSfXcRJm6wz4=; b=SzRKO4rJRplM kUfb6UJhndhoSyqev3dyq9hP9wHd7NeN75582duvF5o+p9k2aSV6OTiYgETRzxE/jM80HU5G4khrF B1veQyK4uUpQiuDAmv3HmTM8A/YcP1bBdMSlfCz/d5QaW3lItL0UjykyfXu/Nn80q+qtg46q8LzxR 66LlvEX7f0aSktVJoDcQcmaFXC32SslJfqX3HnyeD5Dpv/V275UJ6wDFRO3M6BMiT6FbxHxI1ZqC6 zla9fPcqvh8M5XV9GfxxVI1BrWaG8XdSbNBLO/CF6Ta+0c0t6qA8jl/mO9pXeiKRrUaFjiBHiGuX/ cbVdzPpmUaX/hA0EN8eiHw==; Date: Mon, 20 May 2024 14:30:56 +0300 Message-Id: <86pltgaff3.fsf@gnu.org> From: Eli Zaretskii To: Vincent Lefevre In-Reply-To: <20240520010748.GB323381@qaa.vinc17.org> (message from Vincent Lefevre on Mon, 20 May 2024 03:07:48 +0200) Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions References: <20240520010748.GB323381@qaa.vinc17.org> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Mon, 20 May 2024 03:07:48 +0200 > From: Vincent Lefevre > > When doing a backup, GNU Emacs renames the file (according to strace). > Under some conditions, the file can be lost. > > I noticed that due to a bug in the combination between Emacs and gpg, > where the "save" operation cannot be completed. > > To reproduce with "emacs -Q", do for a file that is not under version > control (otherwise --eval="(setq vc-make-backup-files t)" is needed): > > 1. emacs -Q file.gpg > 2. Modify the file. > 3. Save with C-x C-s > > At this point, gpg gets interactive, with a question > > Untrusted key [...]. Use anyway? (y or n) > > and one can see that the file "file.gpg" has been renamed to > "file.gpg~". > > And it may happen that the save operation will never be completed, > e.g. because of a bug like > > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1071372 > > (where gpg never terminates) or because Emacs may be killed before > the user could complete the save operation. Does it help to customize the variable backup-by-copying to a non-nil value? From debbugs-submit-bounces@debbugs.gnu.org Tue May 21 04:44:57 2024 Received: (at 71074) by debbugs.gnu.org; 21 May 2024 08:44:57 +0000 Received: from localhost ([127.0.0.1]:47925 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9L7A-0005Ws-Uy for submit@debbugs.gnu.org; Tue, 21 May 2024 04:44:57 -0400 Received: from joooj.vinc17.net ([155.133.131.76]:46674) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9L77-0005Wm-TZ for 71074@debbugs.gnu.org; Tue, 21 May 2024 04:44:55 -0400 Received: from smtp-qaa.vinc17.net (2a02-8428-1b1d-4d01-96a9-491d-7b48-ba31.rev.sfr.net [IPv6:2a02:8428:1b1d:4d01:96a9:491d:7b48:ba31]) by joooj.vinc17.net (Postfix) with ESMTPSA id 8AF7E4AF; Tue, 21 May 2024 10:44:17 +0200 (CEST) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 9F01DCA011C; Tue, 21 May 2024 10:44:16 +0200 (CEST) Date: Tue, 21 May 2024 10:44:16 +0200 From: Vincent Lefevre To: Eli Zaretskii Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions Message-ID: <20240521084416.GH2665@qaa.vinc17.org> References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86pltgaff3.fsf@gnu.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.13+76 (1f3da810) vl-167818 (2024-04-20) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 2024-05-20 14:30:56 +0300, Eli Zaretskii wrote: > Does it help to customize the variable backup-by-copying to a non-nil > value? Yes, but note that a useless backup is done because the file will not necessarily be saved (if the save operation is canceled via an interactive question or due to Debian bug 1071372). Whether renaming or copying, the backup should be done just before actually saving. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) From debbugs-submit-bounces@debbugs.gnu.org Tue May 21 08:12:28 2024 Received: (at 71074) by debbugs.gnu.org; 21 May 2024 12:12:28 +0000 Received: from localhost ([127.0.0.1]:48838 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9OLx-00053u-Fw for submit@debbugs.gnu.org; Tue, 21 May 2024 08:12:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9OLs-00053o-9h for 71074@debbugs.gnu.org; Tue, 21 May 2024 08:12:24 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9OLh-0006mR-2o; Tue, 21 May 2024 08:12:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=FxDGTJsS2amh6cLDVrgx3F4xeO4hS32g2M84hgE9AHI=; b=r9WLPkHBzyit cgUbTyCMkKHKF5eKyomwRnu3xYBWEjNKfIZAuyYsQQ9KsqA16P+pU+LQ+FXilmn2sg80aBGO/iX5k E1uHpOleKPNHLvqHrrMyPsqXloIh7NZ6SQinSn53gFrQxkHaQvmYaaV5LlUxJh5GoBceIu2eafR/0 8362Kxhzi+POhE3OvCwkfFSQTFYVzFm02Z4dDDCb2QNt/BGMdjc9Ze7mcojJzBhqQrxcsgZsTky2K ww/ZLVyPeMZgSrAeixCTTH+BgksjZt/QYipT6I1DQeZnwwsX2r5WuvUR2rQ909NivKVnVcQauD2rg 8Rj/ryxQ9sUc1PYjQ556Ng==; Date: Tue, 21 May 2024 15:12:05 +0300 Message-Id: <86msoj8iui.fsf@gnu.org> From: Eli Zaretskii To: Vincent Lefevre In-Reply-To: <20240521084416.GH2665@qaa.vinc17.org> (message from Vincent Lefevre on Tue, 21 May 2024 10:44:16 +0200) Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> <20240521084416.GH2665@qaa.vinc17.org> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Tue, 21 May 2024 10:44:16 +0200 > From: Vincent Lefevre > Cc: 71074@debbugs.gnu.org > > On 2024-05-20 14:30:56 +0300, Eli Zaretskii wrote: > > Does it help to customize the variable backup-by-copying to a non-nil > > value? > > Yes, but note that a useless backup is done because the file will > not necessarily be saved (if the save operation is canceled via > an interactive question or due to Debian bug 1071372). Sure, but if the danger is to lose the file due to some calamity, a useless backup is a very minor disadvantage, don't you agree? > Whether renaming or copying, the backup should be done just before > actually saving. We already do that. However, backup+save is not an atomic operation, and as long as it is not atomic, there's always a window of opportunity for some catastrophe, like a system crash or Emacs being killed, to happen in-between. Moreover, Emacs being Emacs, with its high degree of customization, some feature can customize either backup or save (or both) in a way that makes the above-mentioned window very wide. That's what happened in the case you reported: epa-file overrides write-contents, the Emacs primitive that actually writes the buffer to a file, with its own version, and that's why you get that prompt about untrusted key. We cannot avoid such situations, because if we disallow customizations like that, Emacs will no longer be Emacs. In fact, you yourself use a similar feature, when you define find-backup-file-name to force all the backup files to go to a specific directory. Such a function could in theory do anything it wants, including prompting you and whatnot, thus prolonging the window between the backup and the save. So I don't see how we could significantly change this situation without losing very useful features, and therefore I think backup-by-copying is the best solution we can provide in such cases. From debbugs-submit-bounces@debbugs.gnu.org Tue May 21 08:42:41 2024 Received: (at 71074) by debbugs.gnu.org; 21 May 2024 12:42:41 +0000 Received: from localhost ([127.0.0.1]:48969 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9OpF-0005MF-JF for submit@debbugs.gnu.org; Tue, 21 May 2024 08:42:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45140) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9OpE-0005M5-1V for 71074@debbugs.gnu.org; Tue, 21 May 2024 08:42:41 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9Op3-0003gI-Bm; Tue, 21 May 2024 08:42:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=J+04GhE+uHMe91AJY5hElz65oV4URKWVMq8g3t9nt4U=; b=P4w91AQciVTd tDSOPDXnOf3NaataJwAYMRCvRm5iDj3+Ebq8VKsUjjPdER+Vi1pYQ4BPVNeV+aHQiRPik6Q3nO7PD u6C5cSzeKXicwneyiY8qzF/DVQl7/tZ8UzqtZQUTs5pUdu6MxFbBt7esQElSzi+rvFF/SD2DRei0w WEZPrt4qyTEJE2o/ObZgtpG010WwJaWAJVGOILNk/7Di8VgiOO22JcFPz67fHUNTdNbbsOb6aC5iP lxPg0iDutQT6XuorUCaZiRY66lAAlUqNNDrX11dMjgHqU2t0kxbaGFl4jQHEzIjEfFN6fmdcG0+Tw 8ybqyCmNe0vG0f3PNCSpXw==; Date: Tue, 21 May 2024 15:42:26 +0300 Message-Id: <86ikz78hfx.fsf@gnu.org> From: Eli Zaretskii To: vincent@vinc17.net In-Reply-To: <86msoj8iui.fsf@gnu.org> (message from Eli Zaretskii on Tue, 21 May 2024 15:12:05 +0300) Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> <20240521084416.GH2665@qaa.vinc17.org> <86msoj8iui.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 71074@debbugs.gnu.org > Date: Tue, 21 May 2024 15:12:05 +0300 > From: Eli Zaretskii > > So I don't see how we could significantly change this situation > without losing very useful features, and therefore I think > backup-by-copying is the best solution we can provide in such cases. Actually, an alternative is to customize file-precious-flag to a non-nil value. From debbugs-submit-bounces@debbugs.gnu.org Wed May 22 07:08:59 2024 Received: (at 71074) by debbugs.gnu.org; 22 May 2024 11:08:59 +0000 Received: from localhost ([127.0.0.1]:55230 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9jq6-0004Am-Tw for submit@debbugs.gnu.org; Wed, 22 May 2024 07:08:59 -0400 Received: from joooj.vinc17.net ([155.133.131.76]:55904) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9jq3-0004Ac-9v for 71074@debbugs.gnu.org; Wed, 22 May 2024 07:08:57 -0400 Received: from smtp-qaa.vinc17.net (2a02-8428-1b1d-4d01-96a9-491d-7b48-ba31.rev.sfr.net [IPv6:2a02:8428:1b1d:4d01:96a9:491d:7b48:ba31]) by joooj.vinc17.net (Postfix) with ESMTPSA id 59D8C602; Wed, 22 May 2024 13:08:18 +0200 (CEST) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 1A403CA00B3; Wed, 22 May 2024 13:08:18 +0200 (CEST) Date: Wed, 22 May 2024 13:08:18 +0200 From: Vincent Lefevre To: Eli Zaretskii Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions Message-ID: <20240522110818.GU2665@qaa.vinc17.org> References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> <20240521084416.GH2665@qaa.vinc17.org> <86msoj8iui.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86msoj8iui.fsf@gnu.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.13+76 (1f3da810) vl-167818 (2024-04-20) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 2024-05-21 15:12:05 +0300, Eli Zaretskii wrote: > > Date: Tue, 21 May 2024 10:44:16 +0200 > > From: Vincent Lefevre > > Cc: 71074@debbugs.gnu.org > > > > On 2024-05-20 14:30:56 +0300, Eli Zaretskii wrote: > > > Does it help to customize the variable backup-by-copying to a non-nil > > > value? > > > > Yes, but note that a useless backup is done because the file will > > not necessarily be saved (if the save operation is canceled via > > an interactive question or due to Debian bug 1071372). > > Sure, but if the danger is to lose the file due to some calamity, a > useless backup is a very minor disadvantage, don't you agree? Yes, but this could be a future improvement. > > Whether renaming or copying, the backup should be done just before > > actually saving. > > We already do that. By "just before", I mean that there should not be any system call between a backup and the write of the file. BTW, there is actually an issue with the backup system: the backup is done only before the *first* save-buffer, while an issue might appear only for a subsequent save-buffer. > However, backup+save is not an atomic operation, and as long as it > is not atomic, there's always a window of opportunity for some > catastrophe, like a system crash or Emacs being killed, to happen > in-between. Yes, but if the window is restricted to the minimum, the probability of a system crash / killed Emacs is significantly reduced. I suppose that file-precious-flag as you suggested later may be the ultimate solution. > Moreover, Emacs being Emacs, with its high degree of customization, > some feature can customize either backup or save (or both) in a way > that makes the above-mentioned window very wide. That's what happened > in the case you reported: epa-file overrides write-contents, the Emacs > primitive that actually writes the buffer to a file, with its own > version, and that's why you get that prompt about untrusted key. So, does this mean that file-precious-flag doesn't work here? But perhaps that's a bug in epa-file, which should ensure that by default, the pathname isn't removed (due to the backup by rename) until the new file can be written. This means that it currently does the backup too early. > We cannot avoid such situations, because if we disallow customizations > like that, Emacs will no longer be Emacs. In fact, you yourself use a > similar feature, when you define find-backup-file-name to force all > the backup files to go to a specific directory. Such a function could > in theory do anything it wants, including prompting you and whatnot, > thus prolonging the window between the backup and the save. But customizations should be implemented properly to avoid issues. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon) From debbugs-submit-bounces@debbugs.gnu.org Wed May 22 09:25:49 2024 Received: (at 71074) by debbugs.gnu.org; 22 May 2024 13:25:49 +0000 Received: from localhost ([127.0.0.1]:55947 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9lyX-0002rh-5V for submit@debbugs.gnu.org; Wed, 22 May 2024 09:25:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9lyU-0002rb-Qw for 71074@debbugs.gnu.org; Wed, 22 May 2024 09:25:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9lyJ-0008JR-Do; Wed, 22 May 2024 09:25:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=yFNGt59zYnRlP3AD1RNWMvnnJ7t1a99+H9d2XTLG6JA=; b=Rwiq/ulvEcAA UcPNQm+swcRvG0iTwBqoJaURh4EVASD7ixVFjxCpPSehbM3HxBN2TiNcWeOq74iIM/7lq9dvwhF/C N5Ymy4lhu/UhhJEQvcaG3g5kOSBACLJnZBme80tTMRUKdq1PRfyF5P2xy37HP8Rmd0H6mC5OKiRuQ hyo+vubDtHoRhJlxKo6T4Bw7cvP7rXZ3pgZ9ignS7BjaH6HMBdo1wNa+vdTudeGzLNNW0QwGIPzLh 6vStNGc5ZfsSlLBGp+J+jAptQHxDhx2jO9aYU2hnTEv0imcASlclstD8VqQIMrjvCYUaTWqB356iI Pwv/SqhNqJWC2a96R/Ji1w==; Date: Wed, 22 May 2024 16:25:24 +0300 Message-Id: <86ed9u6ksb.fsf@gnu.org> From: Eli Zaretskii To: Vincent Lefevre In-Reply-To: <20240522110818.GU2665@qaa.vinc17.org> (message from Vincent Lefevre on Wed, 22 May 2024 13:08:18 +0200) Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> <20240521084416.GH2665@qaa.vinc17.org> <86msoj8iui.fsf@gnu.org> <20240522110818.GU2665@qaa.vinc17.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Wed, 22 May 2024 13:08:18 +0200 > From: Vincent Lefevre > Cc: 71074@debbugs.gnu.org > > > > Whether renaming or copying, the backup should be done just before > > > actually saving. > > > > We already do that. > > By "just before", I mean that there should not be any system call > between a backup and the write of the file. I don't see how this could be done in Emacs, sorry. But if you or someone has practical ideas, let's hear them. > BTW, there is actually an issue with the backup system: the backup > is done only before the *first* save-buffer, while an issue might > appear only for a subsequent save-buffer. This is how backups in Emacs work. Catastrophes do happen, but at least Emacs attempts to auto-save everything when it is about to crash. It doesn't always work, depending on the reason for the crash. > > Moreover, Emacs being Emacs, with its high degree of customization, > > some feature can customize either backup or save (or both) in a way > > that makes the above-mentioned window very wide. That's what happened > > in the case you reported: epa-file overrides write-contents, the Emacs > > primitive that actually writes the buffer to a file, with its own > > version, and that's why you get that prompt about untrusted key. > > So, does this mean that file-precious-flag doesn't work here? AFAICT, it does work. Its purpose is to avoid overwriting the original file until the new stuff was successfully written to disk. > > We cannot avoid such situations, because if we disallow customizations > > like that, Emacs will no longer be Emacs. In fact, you yourself use a > > similar feature, when you define find-backup-file-name to force all > > the backup files to go to a specific directory. Such a function could > > in theory do anything it wants, including prompting you and whatnot, > > thus prolonging the window between the backup and the save. > > But customizations should be implemented properly to avoid issues. I don't see how. E.g., if we let users and packages customize how files are backed up, it's anyone's guess what will happen inside the backup-buffer call and how much time will that take. What would be a "proper implementation" that still allows such customizations? But again, practical ideas are welcome. From debbugs-submit-bounces@debbugs.gnu.org Thu May 23 10:50:14 2024 Received: (at 71074) by debbugs.gnu.org; 23 May 2024 14:50:14 +0000 Received: from localhost ([127.0.0.1]:59375 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sA9lm-0003bJ-0w for submit@debbugs.gnu.org; Thu, 23 May 2024 10:50:14 -0400 Received: from cventin.lip.ens-lyon.fr ([140.77.13.17]:39232) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sA9li-0003bA-5z for 71074@debbugs.gnu.org; Thu, 23 May 2024 10:50:13 -0400 Received: from vlefevre by cventin.lip.ens-lyon.fr with local (Exim 4.97) (envelope-from ) id 1sA9la-000000005ze-0aas; Thu, 23 May 2024 16:50:02 +0200 Date: Thu, 23 May 2024 16:50:02 +0200 From: Vincent Lefevre To: Eli Zaretskii Subject: Re: bug#71074: 29.3; When doing a backup, the file is missing during interactive questions Message-ID: <20240523145002.GA2163@cventin.lip.ens-lyon.fr> References: <20240520010748.GB323381@qaa.vinc17.org> <86pltgaff3.fsf@gnu.org> <20240521084416.GH2665@qaa.vinc17.org> <86msoj8iui.fsf@gnu.org> <20240522110818.GU2665@qaa.vinc17.org> <86ed9u6ksb.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86ed9u6ksb.fsf@gnu.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.13+76 (1f3da810) vl-167818 (2024-04-20) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 71074 Cc: 71074@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 2024-05-22 16:25:24 +0300, Eli Zaretskii wrote: > > Date: Wed, 22 May 2024 13:08:18 +0200 > > From: Vincent Lefevre > > Cc: 71074@debbugs.gnu.org > > > > > > Whether renaming or copying, the backup should be done just before > > > > actually saving. > > > > > > We already do that. > > > > By "just before", I mean that there should not be any system call > > between a backup and the write of the file. > > I don't see how this could be done in Emacs, sorry. But if you or > someone has practical ideas, let's hear them. > > > BTW, there is actually an issue with the backup system: the backup > > is done only before the *first* save-buffer, while an issue might > > appear only for a subsequent save-buffer. > > This is how backups in Emacs work. Catastrophes do happen, but at > least Emacs attempts to auto-save everything when it is about to > crash. It doesn't always work, depending on the reason for the crash. OK, this is actually what I expected to get with the gpg bug. Since the file.gpg file was not restored from the "save-buffer" failure, I expected to get a "#file.gpg#" file for recovery, but there was none. Alternatively, Emacs could have restored the file from the backup. I don't what happened, but I don't see the logic behind Emacs. For instance, when editing a normal file with the Emacs GUI and doing Ctrl-C in the terminal before saving, a recovery file is created. But nothing similar is done with .gpg file (of course, it is not possible to have the unsaved contents because encryption could not be done, but I would expect at least the saved-encrypted version back in this case, instead of neither the file nor a recovery file). > > > Moreover, Emacs being Emacs, with its high degree of customization, > > > some feature can customize either backup or save (or both) in a way > > > that makes the above-mentioned window very wide. That's what happened > > > in the case you reported: epa-file overrides write-contents, the Emacs > > > primitive that actually writes the buffer to a file, with its own > > > version, and that's why you get that prompt about untrusted key. > > > > So, does this mean that file-precious-flag doesn't work here? > > AFAICT, it does work. Its purpose is to avoid overwriting the > original file until the new stuff was successfully written to disk. BTW, it leaves empty files, for instance, in case of gpg error: -rw------- 1 vlefevre vlefevre 0 2024-05-23 15:55:36 tmpSHlCS3 -rw------- 1 vlefevre vlefevre 0 2024-05-23 15:57:00 tmpf5O5RM > > > We cannot avoid such situations, because if we disallow customizations > > > like that, Emacs will no longer be Emacs. In fact, you yourself use a > > > similar feature, when you define find-backup-file-name to force all > > > the backup files to go to a specific directory. Such a function could > > > in theory do anything it wants, including prompting you and whatnot, > > > thus prolonging the window between the backup and the save. > > > > But customizations should be implemented properly to avoid issues. > > I don't see how. E.g., if we let users and packages customize how > files are backed up, it's anyone's guess what will happen inside the > backup-buffer call and how much time will that take. What would be a > "proper implementation" that still allows such customizations? But > again, practical ideas are welcome. I think that this would be more or less equivalent to the file-precious-flag feature. I'm wondering why it is not enabled by default. It seems that the only "issue" is that this breaks the hard links. But hard links seem very rare in practice. If this is really an issue, the file-precious-flag behavior could be conditional to whether the file has hard links. And about "As a side effect, backups are necessarily made by copying.", another possibility could be proposed: a backup by a hardlink (if supported). Since the hardlink will normally be broken, this will normally give no hardlinks at the end, as expected. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)