Add a reusable ensure_dirs() function and use it for DISTDIR initialization.
authorZac Medico <zmedico@gentoo.org>
Thu, 30 Mar 2006 09:41:19 +0000 (09:41 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 30 Mar 2006 09:41:19 +0000 (09:41 -0000)
svn path=/main/trunk/; revision=3040

pym/portage.py
pym/portage_util.py

index 56aa7b2df41873e1f68e603a4eca242b8d071a30..9ce918114bcbd8f50c701b3aecfd60a191f04101 100644 (file)
@@ -2734,30 +2734,7 @@ def doebuild(myebuild,mydo,myroot,mysettings,debug=0,listonly=0,fetchonly=0,clea
                        
                        for x in distdir_dirs:
                                mydir = os.path.join(mysettings["DISTDIR"], x)
-                               try:
-                                       os.makedirs(mydir)
-                               except OSError, oe:
-                                       if errno.EEXIST == oe.errno:
-                                               pass
-                                       elif  oe.errno in (errno.EPERM, errno.EROFS):
-                                               writemsg("!!! %s\n" % oe)
-                                               raise portage_exception.OperationNotPermitted("mkdir '%s'" % mydir)
-                                       else:
-                                               raise
-                               try:
-                                       initial_stat = os.stat(mydir)
-                                       apply_secpass_permissions(mydir,
-                                               gid=portage_gid, mode=dirmode, mask=modemask, stat_cached=initial_stat)
-                                       result_stat = os.stat(mydir)
-                               except OSError, oe:
-                                       if errno.EPERM == oe.errno:
-                                               writemsg("!!! %s\n" % oe)
-                                               raise portage_exception.OperationNotPermitted("stat('%s')" % mydir)
-                                       raise
-                               # Trigger recursion when the top level directory does not
-                               # initially match our permission requirements.
-                               if result_stat.st_gid != initial_stat.st_gid or \
-                               result_stat.st_mode & 07777 != initial_stat.st_mode & 07777:
+                               if portage_util.ensure_dirs(mydir, gid=portage_gid, mode=dirmode, mask=modemask):
                                        writemsg("Adjusting permissions recursively: '%s'\n" % mydir)
                                        def onerror(e):
                                                raise # bail out on the first error that occurs during recursion
index bd8aefeff14f465d05163981acea54e3a5f49769..ae75251869ba4b180536c372ba994c1f83465afc 100644 (file)
@@ -686,3 +686,23 @@ def write_atomic(file_path, content):
        except IOError, ioe:
                f.abort()
                raise ioe
+
+def ensure_dirs(dir_path, *args, **kwargs):
+       """Create a directory and call apply_permissions.
+       Returns True if a directory is created or the permissions needed to be
+       modified, and False otherwise."""
+
+       created_dir = False
+
+       try:
+               os.makedirs(dir_path)
+               created_dir = True
+       except OSError, oe:
+               if errno.EEXIST == oe.errno:
+                       pass
+               elif  oe.errno in (errno.EPERM, errno.EROFS):
+                       raise portage_exception.OperationNotPermitted(str(oe))
+               else:
+                       raise
+       perms_modified = apply_permissions(dir_path, *args, **kwargs)
+       return created_dir or perms_modified