egencache: validate cache dir more
authorZac Medico <zmedico@gentoo.org>
Wed, 7 Sep 2011 16:29:48 +0000 (09:29 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 7 Sep 2011 16:29:48 +0000 (09:29 -0700)
bin/egencache

index bf29474ef50bcc6ac8770ccbe8477cb6f465c948..66854e17e14f09c1edd9b6d5cf793e82be483224 100755 (executable)
@@ -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)