1 |
commit: 5924b7afae7c731abc24a0e16fcd103e680e3e5b |
2 |
Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
3 |
AuthorDate: Wed Oct 2 10:36:49 2013 +0000 |
4 |
Commit: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
5 |
CommitDate: Wed Oct 2 10:36:49 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=5924b7af |
7 |
|
8 |
Bug #418475: Handle PermissionError caused by unreadable /etc/portage/modules. |
9 |
|
10 |
--- |
11 |
pym/portage/env/loaders.py | 26 +++++++++++++++++--------- |
12 |
1 file changed, 17 insertions(+), 9 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py |
15 |
index 372bc12..f869884 100644 |
16 |
--- a/pym/portage/env/loaders.py |
17 |
+++ b/pym/portage/env/loaders.py |
18 |
@@ -1,10 +1,14 @@ |
19 |
# config.py -- Portage Config |
20 |
-# Copyright 2007-2011 Gentoo Foundation |
21 |
+# Copyright 2007-2013 Gentoo Foundation |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
|
24 |
import errno |
25 |
import io |
26 |
import stat |
27 |
+import portage |
28 |
+portage.proxy.lazyimport.lazyimport(globals(), |
29 |
+ 'portage.util:writemsg', |
30 |
+) |
31 |
from portage import os |
32 |
from portage import _encodings |
33 |
from portage import _unicode_decode |
34 |
@@ -149,17 +153,21 @@ class FileLoader(DataLoader): |
35 |
func = self.lineParser |
36 |
for fn in RecursiveFileLoader(self.fname): |
37 |
try: |
38 |
- f = io.open(_unicode_encode(fn, |
39 |
+ with io.open(_unicode_encode(fn, |
40 |
encoding=_encodings['fs'], errors='strict'), mode='r', |
41 |
- encoding=_encodings['content'], errors='replace') |
42 |
+ encoding=_encodings['content'], errors='replace') as f: |
43 |
+ lines = f.readlines() |
44 |
except EnvironmentError as e: |
45 |
- if e.errno not in (errno.ENOENT, errno.ESTALE): |
46 |
+ if e.errno == errno.EACCES: |
47 |
+ writemsg(_("Permission denied: '%s'\n") % fn, noiselevel=-1) |
48 |
+ del e |
49 |
+ elif e.errno in (errno.ENOENT, errno.ESTALE): |
50 |
+ del e |
51 |
+ else: |
52 |
raise |
53 |
- del e |
54 |
- continue |
55 |
- for line_num, line in enumerate(f): |
56 |
- func(line, line_num, data, errors) |
57 |
- f.close() |
58 |
+ else: |
59 |
+ for line_num, line in enumerate(lines): |
60 |
+ func(line, line_num, data, errors) |
61 |
return (data, errors) |
62 |
|
63 |
def lineParser(self, line, line_num, data, errors): |