config: raise PermissionDenied more v2.2.0_alpha161
authorZac Medico <zmedico@gentoo.org>
Thu, 24 Jan 2013 21:53:04 +0000 (13:53 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 24 Jan 2013 21:53:04 +0000 (13:53 -0800)
This enables clear reporting of "Permission Denied" when appropriate,
instead of triggering nonsensical messages about invalid profiles or
repositories.

pym/portage/package/ebuild/_config/LocationsManager.py
pym/portage/package/ebuild/config.py

index 8f88e4909fd46fd939e716685bc92b5f8afa1df0..95a77513404647160d0a597c92fb3347d9c54589 100644 (file)
@@ -18,6 +18,7 @@ from portage.exception import DirectoryNotFound, ParseError
 from portage.localization import _
 from portage.util import ensure_dirs, grabfile, \
        normalize_path, shlex_split, writemsg
+from portage.util._path import exists_raise_eaccess, isdir_raise_eaccess
 from portage.repository.config import parse_layout_conf, \
        _portage1_profiles_allow_directories
 
@@ -77,9 +78,9 @@ class LocationsManager(object):
                                self.config_root, 'etc', 'make.profile')
                        self.config_profile_path = \
                                os.path.join(self.config_root, PROFILE_PATH)
-                       if os.path.isdir(self.config_profile_path):
+                       if isdir_raise_eaccess(self.config_profile_path):
                                self.profile_path = self.config_profile_path
-                               if os.path.isdir(deprecated_profile_path) and not \
+                               if isdir_raise_eaccess(deprecated_profile_path) and not \
                                        os.path.samefile(self.profile_path,
                                        deprecated_profile_path):
                                        # Don't warn if they refer to the same path, since
@@ -92,7 +93,7 @@ class LocationsManager(object):
                                                noiselevel=-1)
                        else:
                                self.config_profile_path = deprecated_profile_path
-                               if os.path.isdir(self.config_profile_path):
+                               if isdir_raise_eaccess(self.config_profile_path):
                                        self.profile_path = self.config_profile_path
                                else:
                                        self.profile_path = None
@@ -132,7 +133,7 @@ class LocationsManager(object):
                self.profiles_complex = tuple(self.profiles_complex)
 
        def _check_var_directory(self, varname, var):
-               if not os.path.isdir(var):
+               if not isdir_raise_eaccess(var):
                        writemsg(_("!!! Error: %s='%s' is not a directory. "
                                "Please correct this.\n") % (varname, var),
                                noiselevel=-1)
@@ -192,7 +193,7 @@ class LocationsManager(object):
                                                files=', '.join(offenders)))
 
                parentsFile = os.path.join(currentPath, "parent")
-               if os.path.exists(parentsFile):
+               if exists_raise_eaccess(parentsFile):
                        parents = grabfile(parentsFile)
                        if not parents:
                                raise ParseError(
@@ -214,7 +215,7 @@ class LocationsManager(object):
                                        # of the current repo, so realpath it.
                                        parentPath = os.path.realpath(parentPath)
 
-                               if os.path.exists(parentPath):
+                               if exists_raise_eaccess(parentPath):
                                        self._addProfile(parentPath, repositories, known_repos)
                                else:
                                        raise ParseError(
@@ -305,7 +306,7 @@ class LocationsManager(object):
                for ov in shlex_split(self.portdir_overlay):
                        ov = normalize_path(ov)
                        profiles_dir = os.path.join(ov, "profiles")
-                       if os.path.isdir(profiles_dir):
+                       if isdir_raise_eaccess(profiles_dir):
                                self.overlay_profiles.append(profiles_dir)
 
                self.profile_locations = [os.path.join(portdir, "profiles")] + self.overlay_profiles
index 0ea0841b24c482a1f4db2f2a8e2ca4cf8a5dabc3..352b2982aed49061014bc44bee159c4fe7daab80 100644 (file)
@@ -46,6 +46,7 @@ from portage.util import ensure_dirs, getconfig, grabdict, \
        grabdict_package, grabfile, grabfile_package, LazyItemsDict, \
        normalize_path, shlex_split, stack_dictlist, stack_dicts, stack_lists, \
        writemsg, writemsg_level, _eapi_cache
+from portage.util._path import exists_raise_eaccess, isdir_raise_eaccess
 from portage.versions import catpkgsplit, catsplit, cpv_getkey, _pkg_str
 
 from portage.package.ebuild._config import special_env_vars
@@ -620,7 +621,7 @@ class config(object):
                                shell_quote_re = re.compile(r"[\s\\\"'$`]")
                                for ov in portdir_overlay:
                                        ov = normalize_path(ov)
-                                       if os.path.isdir(ov):
+                                       if isdir_raise_eaccess(ov):
                                                if shell_quote_re.search(ov) is not None:
                                                        ov = portage._shell_quote(ov)
                                                new_ov.append(ov)
@@ -1006,8 +1007,8 @@ class config(object):
                                                noiselevel=-1)
 
                profile_broken = not self.profile_path or \
-                       not os.path.exists(os.path.join(self.profile_path, "parent")) and \
-                       os.path.exists(os.path.join(self["PORTDIR"], "profiles"))
+                       not exists_raise_eaccess(os.path.join(self.profile_path, "parent")) and \
+                       exists_raise_eaccess(os.path.join(self["PORTDIR"], "profiles"))
 
                if profile_broken:
                        abs_profile_path = None