Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Matt Turner <mattst88@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH gentoolkit] bin: Add merge-driver-ekeyword
Date: Tue, 29 Dec 2020 01:09:20
Message-Id: 4fc71b46-904a-a3a0-46b6-1df64b19fde8@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH gentoolkit] bin: Add merge-driver-ekeyword by Matt Turner
1 On 12/28/20 3:15 PM, Matt Turner wrote:
2 > +def apply_keyword_changes(ebuild: str, pathname: str,
3 > + changes: List[Tuple[Optional[str],
4 > + Optional[str]]]) -> int:
5 > + result: int = 0
6 > +
7 > + # ekeyword will only modify files named *.ebuild, so make a symlink
8 > + ebuild_symlink: str = os.path.basename(pathname)
9 > + os.symlink(ebuild, ebuild_symlink)
10
11 Are we sure that the current working directory is an entirely safe place
12 to create this symlink? A simple fix would be to use
13 tempfile.TemporaryDirectory to create a temporary directory to hold the
14 symlink. Or, we could change ekeyword to assume that an argument is an
15 ebuild if os.path.isfile(arg) succeeds.
16
17 > + for removals, additions in changes:
18 > + args = []
19 > + for rem in removals:
20 > + # Drop leading '~' and '-' characters and prepend '^'
21 > + i = 1 if rem[0] in ('~', '-') else 0
22 > + args.append('^' + rem[i:])
23 > + if additions:
24 > + args.extend(additions)
25 > + args.append(ebuild_symlink)
26 > +
27 > + result = ekeyword.main(args)
28 > + if result != 0:
29 > + break
30 > +
31 > + os.remove(ebuild_symlink)
32 > + return result
33
34
35 --
36 Thanks,
37 Zac

Attachments

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

Replies