From: Zac Medico Date: Wed, 20 Jun 2007 05:45:31 +0000 (-0000) Subject: For bug #180165, make portageq print a "Permission denied" error when appropriate... X-Git-Tag: v2.1.3~204 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=18792bbde65228ca97fc15b5686d6175b806e925;p=portage.git For bug #180165, make portageq print a "Permission denied" error when appropriate and make has_version die if portageq has an unexpected exit code. (trunk r6880:6882) svn path=/main/branches/2.1.2/; revision=6885 --- diff --git a/bin/ebuild.sh b/bin/ebuild.sh index 029d46a2f..6ea33964c 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -190,11 +190,19 @@ has_version() { fi # return shell-true/shell-false if exists. # Takes single depend-type atoms. - if "${PORTAGE_BIN_PATH}/portageq" 'has_version' "${ROOT}" "$1"; then - return 0 - else - return 1 - fi + "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1" + local retval=$? + case "${retval}" in + 0) + return 0 + ;; + 1) + return 1 + ;; + *) + die "unexpected portageq exit code: ${retval}" + ;; + esac } portageq() { diff --git a/bin/emerge b/bin/emerge index 27a48ee2c..0084dded9 100755 --- a/bin/emerge +++ b/bin/emerge @@ -5582,5 +5582,10 @@ def emerge_main(): post_emerge(settings, mtimedb, 0) if __name__ == "__main__": - retval = emerge_main() + from portage_exception import PermissionDenied + try: + retval = emerge_main() + except PermissionDenied, e: + sys.stderr.write("Permission denied: '%s'\n" % str(e)) + sys.exit(e.errno) sys.exit(retval) diff --git a/bin/portageq b/bin/portageq index de2a24c12..1a59af8bc 100755 --- a/bin/portageq +++ b/bin/portageq @@ -22,7 +22,7 @@ except KeyboardInterrupt: import os import types - +import portage_exception #----------------------------------------------------------------------------- # # To add functionality to this tool, add a function below. @@ -342,6 +342,9 @@ def main(): except KeyError: usage(sys.argv) sys.exit(os.EX_USAGE) + except portage_exception.PermissionDenied, e: + sys.stderr.write("Permission denied: '%s'\n" % str(e)) + sys.exit(e.errno) main() diff --git a/pym/portage.py b/pym/portage.py index ea3fba2fa..054435bff 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -185,7 +185,14 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli mtime = pathstat[stat.ST_MTIME] else: raise portage_exception.DirectoryNotFound(mypath) - except (IOError,OSError,portage_exception.PortageException): + except EnvironmentError, e: + if e.errno == portage_exception.PermissionDenied.errno: + raise portage_exception.PermissionDenied(mypath) + del e + if EmptyOnError: + return [], [] + return None, None + except portage_exception.PortageException: if EmptyOnError: return [], [] return None, None @@ -199,8 +206,6 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli if e.errno != errno.EACCES: raise del e - if EmptyOnError: - return [], [] raise portage_exception.PermissionDenied(mypath) ftype = [] for x in list: diff --git a/pym/portage_exception.py b/pym/portage_exception.py index 4be72cf96..3d590a563 100644 --- a/pym/portage_exception.py +++ b/pym/portage_exception.py @@ -53,6 +53,7 @@ class OperationNotPermitted(PortageException): """An operation was not permitted operating system""" class PermissionDenied(PortageException): + from errno import EACCES as errno """Permission denied""" class ReadOnlyFileSystem(PortageException):