diff options
-rw-r--r-- | pym/portage.py | 24 | ||||
-rw-r--r-- | pym/portage_util.py | 43 |
2 files changed, 45 insertions, 22 deletions
diff --git a/pym/portage.py b/pym/portage.py index 87810a22b..b5f7a68a0 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -75,7 +75,7 @@ try: portage_uid, portage_gid import portage_util - from portage_util import atomic_ofstream, apply_secpass_permissions, \ + from portage_util import atomic_ofstream, apply_secpass_permissions, apply_recursive_permissions, \ dump_traceback, getconfig, grabdict, grabdict_package, grabfile, grabfile_package, \ map_dictlist_vals, pickle_read, pickle_write, stack_dictlist, stack_dicts, stack_lists, \ unique_array, varexpand, writedict, writemsg, writemsg_stdout, write_atomic @@ -2840,26 +2840,8 @@ def doebuild(myebuild,mydo,myroot,mysettings,debug=0,listonly=0,fetchonly=0,clea except portage_exception.FileNotFound, e: writemsg("File Not Found: '%s'\n" % str(e)) - def onerror(oe): - writemsg("%s\n" % str(oe)) - for dirpath, dirnames, filenames in os.walk( - os.path.join(mysettings["DISTDIR"], "cvs-src"), onerror=onerror): - try: - apply_secpass_permissions(dirpath, - gid=portage_gid, mode=02770, mask=02) - except portage_exception.OperationNotPermitted, e: - writemsg("Operation Not Permitted: %s\n" % str(e)) - except portage_exception.FileNotFound, e: - writemsg("File Not Found: '%s'\n" % str(e)) - - for name in filenames: - try: - apply_secpass_permissions(os.path.join(dirpath, name), - gid=portage_gid, mode=0660, mask=02) - except portage_exception.OperationNotPermitted, e: - writemsg("Operation Not Permitted: %s\n" % str(e)) - except portage_exception.FileNotFound, e: - writemsg("File Not Found: '%s'\n" % str(e)) + apply_recursive_permissions(os.path.join(mysettings["DISTDIR"], "cvs-src"), + gid=portage_gid, dirmode=02770, dirmask=02, filemode=0660, filemask=02) # Only try and fetch the files if we are going to need them ... otherwise, # if user has FEATURES=noauto and they run `ebuild clean unpack compile install`, diff --git a/pym/portage_util.py b/pym/portage_util.py index 9956b107d..aa84fa74e 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -2,7 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/pym/portage_util.py,v 1.11.2.6 2005/04/23 07:26:04 jstubbs Exp $ -from portage_exception import FileNotFound, OperationNotPermitted +from portage_exception import PortageException, FileNotFound, OperationNotPermitted import sys,string,shlex,os,errno try: @@ -520,6 +520,47 @@ def apply_stat_permissions(filename, newstat, **kwargs): return apply_secpass_permissions(filename, uid=newstat.st_uid, gid=newstat.st_gid, mode=newstat.st_mode, **kwargs) +def apply_recursive_permissions(top, uid=-1, gid=-1, + dirmode=-1, dirmask=-1, filemode=-1, filemask=-1, onerror=None): + """A wrapper around apply_secpass_permissions that applies permissions + recursively. If optional argument onerror is specified, it should be a + function; it will be called with one argument, a PortageException instance. + Returns True if all permissions are applied and False if some are left + unapplied.""" + + if onerror is None: + # Default behavior is to dump errors to stderr so they won't + # go unnoticed. Callers can pass in a quiet instance. + def onerror(e): + if isinstance(e, OperationNotPermitted): + writemsg("Operation Not Permitted: %s\n" % str(e)) + elif isinstance(e, FileNotFound): + writemsg("File Not Found: '%s'\n" % str(e)) + else: + raise + + all_applied = True + for dirpath, dirnames, filenames in os.walk(top): + try: + applied = apply_secpass_permissions(dirpath, + uid=uid, gid=gid, mode=dirmode, mask=dirmask) + if not applied: + all_applied = False + except PortageException, e: + all_applied = False + onerror(e) + + for name in filenames: + try: + applied = apply_secpass_permissions(os.path.join(dirpath, name), + uid=uid, gid=gid, mode=filemode, mask=filemask) + if not applied: + all_applied = False + except PortageException, e: + all_applied = False + onerror(e) + return all_applied + def apply_secpass_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1, stat_cached=None): """A wrapper around apply_permissions that uses secpass and simple |