diff options
author | Zac Medico <zmedico@gentoo.org> | 2006-03-30 09:41:19 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2006-03-30 09:41:19 +0000 |
commit | 71cfafbd5fb34d125cdfba7b68a5401e30218c9b (patch) | |
tree | ac69334f5e97ba76fe5f1b2004087a56dc18fc00 | |
parent | fddfcec8f370e37cd1518ad0b975a886dc5a28a2 (diff) | |
download | portage-71cfafbd5fb34d125cdfba7b68a5401e30218c9b.tar.gz portage-71cfafbd5fb34d125cdfba7b68a5401e30218c9b.tar.bz2 portage-71cfafbd5fb34d125cdfba7b68a5401e30218c9b.zip |
Add a reusable ensure_dirs() function and use it for DISTDIR initialization.
svn path=/main/trunk/; revision=3040
-rw-r--r-- | pym/portage.py | 25 | ||||
-rw-r--r-- | pym/portage_util.py | 20 |
2 files changed, 21 insertions, 24 deletions
diff --git a/pym/portage.py b/pym/portage.py index 56aa7b2df..9ce918114 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -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 diff --git a/pym/portage_util.py b/pym/portage_util.py index bd8aefeff..ae7525186 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -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 |