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 |