1 |
commit: 284ec5d603c713509534fe6230964decf8a7468a |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Mar 27 15:02:12 2013 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Mar 27 15:02:12 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=284ec5d6 |
7 |
|
8 |
getconfig: handle recursive PermissionDenied |
9 |
|
10 |
--- |
11 |
pym/portage/util/__init__.py | 22 +++++++++++++++++++--- |
12 |
1 files changed, 19 insertions(+), 3 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py |
15 |
index 59d4fa4..7c16b7b 100644 |
16 |
--- a/pym/portage/util/__init__.py |
17 |
+++ b/pym/portage/util/__init__.py |
18 |
@@ -564,6 +564,18 @@ _invalid_var_name_re = re.compile(r'^\d|\W') |
19 |
def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, |
20 |
recursive=False): |
21 |
|
22 |
+ is_dir = False |
23 |
+ if recursive: |
24 |
+ try: |
25 |
+ is_dir = stat.S_ISDIR(os.stat(mycfg).st_mode) |
26 |
+ except OSError as e: |
27 |
+ if e.errno == PermissionDenied.errno: |
28 |
+ raise PermissionDenied(mycfg) |
29 |
+ elif e.errno in (errno.ENOENT, errno.ESTALE, errno.EISDIR): |
30 |
+ return None |
31 |
+ else: |
32 |
+ raise |
33 |
+ |
34 |
if isinstance(expand, dict): |
35 |
# Some existing variable definitions have been |
36 |
# passed in, for use in substitutions. |
37 |
@@ -573,11 +585,15 @@ def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, |
38 |
expand_map = {} |
39 |
mykeys = {} |
40 |
|
41 |
- if recursive and os.path.isdir(mycfg): |
42 |
- # Use source commands so that syntax error messages |
43 |
+ if recursive and is_dir: |
44 |
+ # Emulate source commands so that syntax error messages |
45 |
# can display real file names and line numbers. |
46 |
+ def onerror(e): |
47 |
+ if e.errno == PermissionDenied.errno: |
48 |
+ raise PermissionDenied(mycfg) |
49 |
+ |
50 |
recursive_files = [] |
51 |
- for parent, dirs, files in os.walk(mycfg): |
52 |
+ for parent, dirs, files in os.walk(mycfg, onerror=onerror): |
53 |
try: |
54 |
parent = _unicode_decode(parent, |
55 |
encoding=_encodings['fs'], errors='strict') |