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 31321 invoked from network); 5 Jun 2020 02:08:31 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2020 02:08:31 -0000 Received: (qmail 29559 invoked by alias); 5 Jun 2020 02:08:26 -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: 45977 Received: (qmail 1688 invoked by uid 1010); 5 Jun 2020 02:08:26 -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 0.717489 secs); 05 Jun 2020 02:08:26 -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: gggruggvucftvghtrhhoucdtuddrgeduhedrudegvddghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthejtddtredtvdenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhepfeduteegveehvdfhteevtedvudeludeijeeuudeujeejtdet uedtjefhtdfgieetnecukfhppeejledrudejiedrfeelrdeileenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhh rghhrghfrdhnrghmvg X-ME-Proxy: Date: Fri, 5 Jun 2020 02:07:48 +0000 From: Daniel Shahaf To: Roman Perepelitsa Cc: "zsh-workers@zsh.org" , Martin Tournoij Subject: Re: Any way to allow clobbering empty files when noclobber is set? Message-ID: <20200605020748.635b9bb3@tarpaulin.shahaf.local2> In-Reply-To: References: <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> 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=US-ASCII Content-Transfer-Encoding: 7bit Roman Perepelitsa wrote on Thu, 04 Jun 2020 07:41 +0200: > The regular noclobber can use O_CREAT | O_EXCL to avoid races. How > would any of the proposed modifications work? That is, how to > implement unlink-if-empty without ever unlinking non-empty files? I don't think that's possible: it'd require an atomic stat-and-conditionally-unlink operation, and I don't think there's a syscall for this. fstatat(2)-then-unlinkat(2) gets close, but it's still racy. Good point. > Or how to implement clobber-if-empty without ever clobbering non-empty > files? By using a non-clobbering open(), then calling fstat() on the open fd. If it's zero length, just carry on. If it's not zero length, close() it and report an error. Cheers, Daniel