From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5078 invoked from network); 5 Jun 2020 03:11:09 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2020 03:11:09 -0000 Received: (qmail 8092 invoked by alias); 5 Jun 2020 03:11:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45979 Received: (qmail 23820 invoked by uid 1010); 5 Jun 2020 03:11:00 -0000 X-Qmail-Scanner-Diagnostics: from wout5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25828. spamassassin: 3.4.4. Clear:RC:0(64.147.123.21):SA:0(-2.6/5.0):. Processed in 5.376343 secs); 05 Jun 2020 03:11:00 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudegvddgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthhqtddtredtjeenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhephfelgfdtvedujeelgeejheeggfekueeigfdvvdfghfdvleek uefgledtffduveevnecuffhomhgrihhnpegvgigrmhhplhgvrdgtohhmnecukfhppeejle drudejiedrfeelrdeileenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Date: Fri, 5 Jun 2020 03:10:13 +0000 From: Daniel Shahaf To: Bart Schaefer Cc: "zsh-workers@zsh.org" , Martin Tournoij Subject: Re: Any way to allow clobbering empty files when noclobber is set? Message-ID: <20200605031013.16a36d31@tarpaulin.shahaf.local2> In-Reply-To: References: <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <20200604014850.52d241bd@tarpaulin.shahaf.local2> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Bart Schaefer wrote on Wed, 03 Jun 2020 22:00 -0700: > On Wed, Jun 3, 2020 at 9:06 PM Daniel Shahaf wro= te:> > > > > [ Let's call this UNLINK_EMPTY_AFTER_FAILURE for the sake of discussion= . ] > > > > Bart Schaefer wrote on Thu, 04 Jun 2020 02:43 +00:00: =20 > > > > > > How does that user experience differ from HIST_ALLOW_CLOBBER? =20 > > > > Well, for one, because that proposal only takes effect when foo exited > > non-zero, created bar, and bar is zero-sized? =20 >=20 > Fair enough, although (silly example) "false > empty" would remove the > file? Depends on whether ./empty was created by the redirection or not. Files would only be removed if they were created by the redirection operator: % cd "$(mktemp -d)" % ls % false > empty % ls % touch empty % false > empty % ls empty %=20 > Wouldn't you at least want the reason for the unlink to be that the > redirection failed, rather than that the command exited non-zero? >=20 I was thinking that if the command exited non-zero and didn't write anything to stdout, then presumably the file was expected to contain something and is of no use otherwise. This rule DTRT's for diff(1), for example, despite that command exiting non-zero even in some non-error cases. Besides, if the redirection failed=C2=A0=E2=80=94 I assume you mean the ope= n(2) failed=C2=A0=E2=80=94 then isn't the unlink likely to fail as well? > What if the redirection target is a symbolic link? What if it isn't a > plain file? Again, the sequence of events is: 1. bar doesn't exist. 2. Run =C2=ABfoo > bar=C2=BB. As part of this, we create bar as a zero-len= gth plain file. 3. The exit code is non-zero. 4. We stat() bar to see if it's zero-length. If in step=C2=A0#4 we find that bar is not even a plain file, we'll infer that some other process has to have unlinked the plain file we created in step=C2=A02, and we'll leave bar alone. > > > and silently unlinking a file is not very friendly. The /etc/nologin > > > example in your next message comes to mind. =20 > > > > Doesn't this argument also apply to anyone who might set CLOBBER_EMPTY > > and then lose the timestamps on empty files, as in your next message? = =20 >=20 > Yes, but to a lesser degree, because the file is at least still > present if it's presence means something. Okay. Is there a case where leaving around an empty file is worse than removing it? Consider, for example, =C2=ABcurl -o- http://example.com/pre-= repvrop-change > hooks/pre-revprop-change=C2=BB in a Subversion repository. The URL is misspelled, so the command will create an empty pre-revprop-change file, which will allow non-undoable changes to be made. Furthermore, if the command had succeeded, only some such changes would have been allowed; and if the file had not existed, no such changes would have been allowed. Given these semantics, a sysadmin might well prefer to have _no_ pre-revprop-change file rather than to have an empty one. Another example: if I do =C2=ABdiff lorem ipsum > bar=C2=BB and some other = process periodically polls whether bar has been created, the waiting process might take an empty file to mean there's no difference between lorem and ipsum. In this situation, too, it might be better to unlink bar than to leave it around empty. (This could be made less contrived by changing the scenario to someone copying a command from the output of `make -n` and pasting it at the interactive prompt. make(1) targets is another case where empty files and non-existing files behave differently.) Or perhaps something along the lines of =C2=ABtar cf - foo > foo.tar; xz foo.tar=C2=BB in a single command line. (Not a good example, though, since here the user could've used =C2=AB&&=C2=BB.) Cheers, Daniel P.S. In the pre-revprop-change example, the sysadmin should have downloaded the file to a temporary name and then atomically renamed it into place. Some syntactic sugar for this pattern this might be nice=E2=80= =A6