1 |
On 10/21/19 1:43 AM, Michał Górny wrote: |
2 |
> Use real os.walk() when getting filenames for FlatLayout. Unlike |
3 |
> the wrapped Portage module, it return str output for str path parameter, |
4 |
> so we don't have to recode it back and forth. |
5 |
> |
6 |
> Signed-off-by: Michał Górny <mgorny@g.o> |
7 |
> --- |
8 |
> lib/portage/package/ebuild/fetch.py | 3 ++- |
9 |
> 1 file changed, 2 insertions(+), 1 deletion(-) |
10 |
> |
11 |
> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py |
12 |
> index cedf12b19..be277f1a3 100644 |
13 |
> --- a/lib/portage/package/ebuild/fetch.py |
14 |
> +++ b/lib/portage/package/ebuild/fetch.py |
15 |
> @@ -11,6 +11,7 @@ import io |
16 |
> import itertools |
17 |
> import json |
18 |
> import logging |
19 |
> +import os as real_os |
20 |
> import random |
21 |
> import re |
22 |
> import stat |
23 |
> @@ -270,7 +271,7 @@ class FlatLayout(object): |
24 |
> return filename |
25 |
> |
26 |
> def get_filenames(self, distdir): |
27 |
> - for dirpath, dirnames, filenames in os.walk(distdir, |
28 |
> + for dirpath, dirnames, filenames in real_os.walk(distdir, |
29 |
> onerror=_raise_exc): |
30 |
> return iter(filenames) |
31 |
> |
32 |
> |
33 |
|
34 |
The real_os.walk will trigger UnicodeEncodeError if distdir can't be |
35 |
encoded with sys.getfilesystemencoding(). It's an edge case, but |
36 |
generally I prefer to handle it. |
37 |
|
38 |
We can continue to use portage.os for the os.walk call, and turn |
39 |
get_filenames into a generator method like this: |
40 |
|
41 |
for filename in filenames: |
42 |
try: |
43 |
yield portage._unicode_decode(filename, errors='strict') |
44 |
except UnicodeDecodeError: |
45 |
# Ignore it. Distfiles names must have valid UTF8 encoding. |
46 |
pass |
47 |
-- |
48 |
Thanks, |
49 |
Zac |