1 |
On 12/28/20 5:09 PM, Zac Medico wrote: |
2 |
> On 12/28/20 3:15 PM, Matt Turner wrote: |
3 |
>> +def apply_keyword_changes(ebuild: str, pathname: str, |
4 |
>> + changes: List[Tuple[Optional[str], |
5 |
>> + Optional[str]]]) -> int: |
6 |
>> + result: int = 0 |
7 |
>> + |
8 |
>> + # ekeyword will only modify files named *.ebuild, so make a symlink |
9 |
>> + ebuild_symlink: str = os.path.basename(pathname) |
10 |
>> + os.symlink(ebuild, ebuild_symlink) |
11 |
> |
12 |
> Are we sure that the current working directory is an entirely safe place |
13 |
> to create this symlink? A simple fix would be to use |
14 |
> tempfile.TemporaryDirectory to create a temporary directory to hold the |
15 |
> symlink. Or, we could change ekeyword to assume that an argument is an |
16 |
> ebuild if os.path.isfile(arg) succeeds. |
17 |
> |
18 |
>> + for removals, additions in changes: |
19 |
>> + args = [] |
20 |
>> + for rem in removals: |
21 |
>> + # Drop leading '~' and '-' characters and prepend '^' |
22 |
>> + i = 1 if rem[0] in ('~', '-') else 0 |
23 |
>> + args.append('^' + rem[i:]) |
24 |
>> + if additions: |
25 |
>> + args.extend(additions) |
26 |
>> + args.append(ebuild_symlink) |
27 |
>> + |
28 |
>> + result = ekeyword.main(args) |
29 |
|
30 |
Another option is to bypass the ekeyword.main function, like this: |
31 |
|
32 |
try: |
33 |
ekeyword.process_ebuild(pathname, list(map(ekeyword.arg_to_op, args)) |
34 |
except Exception: |
35 |
result = 1 |
36 |
traceback.print_exc() |
37 |
else: |
38 |
result = 0 |
39 |
|
40 |
|
41 |
>> + if result != 0: |
42 |
>> + break |
43 |
>> + |
44 |
>> + os.remove(ebuild_symlink) |
45 |
>> + return result |
46 |
> |
47 |
> |
48 |
|
49 |
|
50 |
-- |
51 |
Thanks, |
52 |
Zac |