From: Zac Medico Date: Wed, 27 Mar 2013 15:02:12 +0000 (-0700) Subject: getconfig: handle recursive PermissionDenied X-Git-Tag: v2.2.0_alpha170~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=284ec5d603c713509534fe6230964decf8a7468a;p=portage.git getconfig: handle recursive PermissionDenied --- diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index 59d4fa4c4..7c16b7bae 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -564,6 +564,18 @@ _invalid_var_name_re = re.compile(r'^\d|\W') def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, recursive=False): + is_dir = False + if recursive: + try: + is_dir = stat.S_ISDIR(os.stat(mycfg).st_mode) + except OSError as e: + if e.errno == PermissionDenied.errno: + raise PermissionDenied(mycfg) + elif e.errno in (errno.ENOENT, errno.ESTALE, errno.EISDIR): + return None + else: + raise + if isinstance(expand, dict): # Some existing variable definitions have been # passed in, for use in substitutions. @@ -573,11 +585,15 @@ def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, expand_map = {} mykeys = {} - if recursive and os.path.isdir(mycfg): - # Use source commands so that syntax error messages + if recursive and is_dir: + # Emulate source commands so that syntax error messages # can display real file names and line numbers. + def onerror(e): + if e.errno == PermissionDenied.errno: + raise PermissionDenied(mycfg) + recursive_files = [] - for parent, dirs, files in os.walk(mycfg): + for parent, dirs, files in os.walk(mycfg, onerror=onerror): try: parent = _unicode_decode(parent, encoding=_encodings['fs'], errors='strict')