From 13ecf921b8e21c1ce98c6da8a5852ba13acfb280 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 20 Jun 2007 00:01:49 +0000 Subject: [PATCH] For bug #180165, make portageq print a "Permission denied" error when appropriate. A PermissionDenied exception is raised from portage.listdir() enven when EmptyOnError is True since errno.EACCES is very likely to indicate a condition that should be reported in any case. svn path=/main/trunk/; revision=6881 --- bin/emerge | 8 +++++++- bin/portageq | 3 +++ pym/portage/__init__.py | 11 ++++++++--- pym/portage/exception.py | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bin/emerge b/bin/emerge index 48f327170..0e12b173e 100755 --- a/bin/emerge +++ b/bin/emerge @@ -13,4 +13,10 @@ except ImportError: if __name__ == "__main__": import sys - sys.exit(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 968cc129a..b9260fed5 100755 --- a/bin/portageq +++ b/bin/portageq @@ -383,6 +383,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/__init__.py b/pym/portage/__init__.py index 31f2f091c..f5a4893c1 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.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): -- 2.26.2