From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 05448138262 for ; Thu, 19 May 2016 22:04:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4450814257; Thu, 19 May 2016 22:04:06 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 45506141F3 for ; Thu, 19 May 2016 22:04:05 +0000 (UTC) Received: from grubbs.orbis-terrarum.net (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B6E0F340C4B for ; Thu, 19 May 2016 22:04:03 +0000 (UTC) Received: (qmail 31136 invoked by uid 10000); 19 May 2016 22:04:03 -0000 Date: Thu, 19 May 2016 22:04:03 +0000 From: "Robin H. Johnson" To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place Message-ID: References: <1463606702-16578-1-git-send-email-aidecoe@gentoo.org> <20160518224314.GH11269@orbis-terrarum.net> <871t4xyax3.fsf@freja.aidecoe.name> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <871t4xyax3.fsf@freja.aidecoe.name> User-Agent: Mutt/1.5.24 (2015-08-30) X-Archives-Salt: 9ab1d797-c830-499f-b094-0627a6b35b06 X-Archives-Hash: b243e24dfcd7b8d4cbf114ebe872ef59 On Thu, May 19, 2016 at 10:50:48PM +0100, Amadeusz Żołnowski wrote: > "Robin H. Johnson" writes: > > 1. > > If your AWK command has an error, then this clobbers the file, a > > better variant, with die, would be: > > awk "$@" "$f" >"${tmpf}" || die "awk failed..." > > cp -f "${tmpf}" "$f" || die "copy back failed" > > Thanks! On the one hand it's a simple function, and on the other hand > there are several things which can go wrong. I will submit corrected > version with unit test. > > Why '-f' is required? Corner cases w/ copying and bad ebuild usage (specifically running ebuild as two different non-root users during development). Mostly habit. Another thought I had, is that if you're using eawk on something in $ROOT, you're also going to clobber ownership, permissions and extended attributes. > >> # @USAGE: > > This calling format is also a problem if they intended to pass multiple > > files to the command, or if they do so accidentally. > > > > Eg, an unprotected glob in the first argument, eg: > > eawk foo* '/foobar/{$1="x"; print $0}' > > > > If foo1 and foo2 existed, this would be considered as: > > awk foo2 /foobar/{$1="x"; print $0}' foo1 > > > > which really will NOT have the desired effect. > > I am aware of this. I considered before: > > a) eawk files... -- awk_args... > b) eawk awk_args -- pattern files... > > making '--' required, but that just complicates usage and function > itself. And anyway isn't it true for any other command with careless > glob use? > > I have documented that function takes a file, not files. The effect of > misuse eawk would be awk error. Although maybe it would be useful to > support multiple files? Then I'd go for variant (b) probably. If we declare the calling format in BSD style: Then this is negated, but means you need to be able to find the first file in the list, which requires parsing the options correctly. Another variation that you haven't considered above is passing multiple programs to awk via -e or -f options, in which case there is no non-option program argument. I agree generally that this is a useful idea, but there's a lot of caveats and corner-cases :-(. -- Robin Hugh Johnson Gentoo Linux: Dev, Infra Lead, Foundation Trustee & Treasurer E-Mail : robbat2@gentoo.org GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85 GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136