From d3aebd49c1a6b893b078f5593677f295a8e77903 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 7 Sep 2011 09:29:48 -0700 Subject: [PATCH] egencache: validate cache dir more --- bin/egencache | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/egencache b/bin/egencache index bf29474ef..66854e17e 100755 --- a/bin/egencache +++ b/bin/egencache @@ -163,9 +163,13 @@ def parse_args(args): parser.error("Not a directory: --config-root='%s'" % \ (options.config_root,)) - if options.cache_dir is not None and not os.path.isdir(options.cache_dir): - parser.error("Not a directory: --cache-dir='%s'" % \ - (options.cache_dir,)) + if options.cache_dir is not None: + if not os.path.isdir(options.cache_dir): + parser.error("Not a directory: --cache-dir='%s'" % \ + (options.cache_dir,)) + if not os.access(options.cache_dir, os.W_OK): + parser.error("Write access denied: --cache-dir='%s'" % \ + (options.cache_dir,)) if options.portdir_overlay is not None and \ options.repo is None: @@ -817,6 +821,18 @@ def egencache_main(args): level=logging.WARNING, noiselevel=-1) settings.features.add('metadata-transfer') + if options.update: + if options.cache_dir is not None: + # already validated earlier + pass + else: + if os.path.isdir(settings["PORTAGE_DEPCACHEDIR"]) and \ + not os.access(settings["PORTAGE_DEPCACHEDIR"], os.W_OK): + writemsg_level("ecachegen: error: " + \ + "write access denied: %s\n" % (settings["PORTAGE_DEPCACHEDIR"],), + level=logging.ERROR, noiselevel=-1) + return 1 + settings.lock() portdb = portage.portdbapi(mysettings=settings) -- 2.26.2