From 92441b7568eedacb4244b6af690e0460bd811eef Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 21 Oct 2007 06:24:20 +0000 Subject: [PATCH] Bug #196537 - Make portageq check that the parameter is an existing directory and exit gracefully if not. (trunk r8195) svn path=/main/branches/2.1.2/; revision=8196 --- bin/portageq | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/portageq b/bin/portageq index 536492fbc..18aa28956 100755 --- a/bin/portageq +++ b/bin/portageq @@ -383,11 +383,20 @@ def main(): sys.exit(os.EX_USAGE) cmd = sys.argv[1] + function = globals().get(cmd) + if function is None: + usage(sys.argv) + sys.exit(os.EX_USAGE) + function = globals()[cmd] + uses_root = getattr(function, "uses_root", False) and len(sys.argv) > 2 + if uses_root: + if not os.path.isdir(sys.argv[2]): + sys.stderr.write("Not a directory: '%s'\n" % sys.argv[2]) + sys.stderr.write("Run portageq with --help for info\n") + sys.stderr.flush() + sys.exit(os.EX_USAGE) + os.environ["ROOT"] = sys.argv[2] try: - function = globals()[cmd] - uses_root = (getattr(function, "uses_root", False) and len(sys.argv) > 2) - if uses_root: - os.environ["ROOT"] = sys.argv[2] global portage try: import portage @@ -400,9 +409,6 @@ def main(): retval = function(sys.argv[2:]) if retval: sys.exit(retval) - 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) -- 2.26.2