Gentoo Archives: gentoo-dev

From: "Amadeusz Żołnowski" <aidecoe@g.o>
To: "Robin H. Johnson" <robbat2@g.o>
Cc: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
Date: Fri, 20 May 2016 17:43:06
Message-Id: 87posgwrqa.fsf@freja.aidecoe.name
In Reply to: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place by "Robin H. Johnson"
1 "Robin H. Johnson" <robbat2@g.o> writes:
2 >> > cp -f "${tmpf}" "$f" || die "copy back failed"
3 >>
4 >> Why '-f' is required?
5 > Corner cases w/ copying and bad ebuild usage (specifically running
6 > ebuild as two different non-root users during development). Mostly
7 > habit.
8
9 Reading:
10
11 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html
12
13 in 3.a.ii it is stated 'cp' should behave like redirection if file
14 already exists, but in case it must actually force (3.a.iii) it does
15 unlink first and in that case permissions of destination are not
16 preserved. So it should either be 'cp' alone or redirection as I already
17 have.
18
19 > Another thought I had, is that if you're using eawk on something in
20 > $ROOT, you're also going to clobber ownership, permissions and
21 > extended attributes.
22
23 Yes, that's why I have used stream redirection in the first place to
24 make it explicit/clear that permissions and attributes are preserved.
25
26 > If we declare the calling format in BSD style:
27 > <args> <files>
28 >
29 > Then this is negated, but means you need to be able to find the first
30 > file in the list, which requires parsing the options correctly.
31
32 Which is not even an option here. (Pun intended.)
33
34 > Another variation that you haven't considered above is passing
35 > multiple programs to awk via -e or -f options, in which case there is
36 > no non-option program argument.
37
38 Indeed. So one of these:
39
40 a) eawk <file> <awk_args...>
41 b) eawk <files...> -- <awk_args...>
42 c) eawk <awk_args...> -- <files...>
43
44 in (b) and (c) "--" is required. This makes it easy to separate options
45 From files without parsing args. With (c) we would have interface almost
46 similar to awk (only that we require "--"). (a) is simplest in
47 implementation and doesn't require "--". I am not sure which is most
48 intuitive. What do you think?
49
50 -- Amadeusz Żołnowski

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies