For bug #180165, make portageq print a "Permission denied" error when appropriate...
authorZac Medico <zmedico@gentoo.org>
Wed, 20 Jun 2007 05:45:31 +0000 (05:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 20 Jun 2007 05:45:31 +0000 (05:45 -0000)
svn path=/main/branches/2.1.2/; revision=6885

bin/ebuild.sh
bin/emerge
bin/portageq
pym/portage.py
pym/portage_exception.py

index 029d46a2f47539673f3a20fd72c082f80c184c2e..6ea33964ce9048b39118793d048d54eab6ca0831 100755 (executable)
@@ -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() {
index 27a48ee2cd11a117c62437745f5dade68a0b2f00..0084dded9313b1c4e585eb33c2b795d4eda27613 100755 (executable)
@@ -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)
index de2a24c12864847bd31f302763cfa0958e0a6646..1a59af8bca2dae485d4d56d5074ac003d71e1b9a 100755 (executable)
@@ -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()
 
index ea3fba2fa2b7493d0ee449f4a66f4627df235700..054435bff526e9718a63fd173705bee6d2a9819f 100644 (file)
@@ -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:
index 4be72cf965e0f3616dcf76e3c625f84cf8b65842..3d590a5638b42fa30a9b13e6a278440f6e7a8728 100644 (file)
@@ -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):