Add a new OperationNotPermitted exception and use it to wrap apply_permissions except...
authorZac Medico <zmedico@gentoo.org>
Tue, 14 Mar 2006 00:38:24 +0000 (00:38 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 14 Mar 2006 00:38:24 +0000 (00:38 -0000)
svn path=/main/trunk/; revision=2871

pym/portage.py
pym/portage_exception.py
pym/portage_util.py

index a15ec1c0ba60b3c762ee63964efb975b70764491..ad040dd70bce206bf353226524962fae34ea32ed 100644 (file)
@@ -1836,14 +1836,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                        can_fetch=False
        else:
                def distdir_perms(filename):
+                       all_applied = True
                        try:
-                               portage_util.apply_secpass_permissions(filename, gid=portage_gid, mode=0775)
-                       except OSError, oe:
-                               if oe.errno == errno.EPERM:
-                                       writemsg("!!! Unable to apply group permissions to '%s'.  Non-root users may experience issues.\n"
-                                       % filename)
-                               else:
-                                       raise oe
+                               all_applied = portage_util.apply_secpass_permissions(filename, gid=portage_gid, mode=0775)
+                       except portage_exceptions.OperationNotPermitted:
+                               all_applied = False
+                       if not all_applied:
+                               writemsg("!!! Unable to apply group permissions to '%s'." + \
+                               "  Non-root users may experience issues.\n" % filename)
                distdir_perms(mysettings["DISTDIR"])
                if use_locks and locks_in_subdir:
                        distlocks_subdir = os.path.join(mysettings["DISTDIR"], locks_in_subdir)
index 27294da6e45f56f5a861365e0791d8d2691cfee3..0d0206df1cbd832846273185e56b998ca5c40c98 100644 (file)
@@ -46,6 +46,8 @@ class FileNotFound(InvalidLocation):
 class DirectoryNotFound(InvalidLocation):
        """A directory was not found when it was expected to exist"""
 
+class OperationNotPermitted(PortageException):
+       """An operation was not permitted operating system"""
 
 class CommandNotFound(PortageException):
        """A required binary was not available or executable"""
index 5b8d87d55405effff2f6666de2561276bbfa0a68..205db9b36cca6426bf33f497076d44bafc62581e 100644 (file)
@@ -2,8 +2,9 @@
 # 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
 
-import sys,string,shlex,os
+import sys,string,shlex,os,errno
 try:
        import cPickle
 except ImportError:
@@ -458,16 +459,23 @@ def apply_permissions(filename, uid=-1, gid=-1, mode=0,
        stat_cached=None):
        """Apply user, group, and mode bits to a file
        if the existing bits do not already match."""
-
-       if stat_cached is None:
-               stat_cached = os.stat(filename)
-
-       if      (uid != -1 and uid != stat_cached.st_uid) or \
-               (gid != -1 and gid != stat_cached.st_gid):
-               os.chown(filename, uid, gid)
-
-       if mode & stat_cached.st_mode != mode:
-               os.chmod(filename, mode | stat_cached.st_mode)
+       try:
+               if stat_cached is None:
+                       stat_cached = os.stat(filename)
+
+               if      (uid != -1 and uid != stat_cached.st_uid) or \
+                       (gid != -1 and gid != stat_cached.st_gid):
+                       os.chown(filename, uid, gid)
+
+               if mode & stat_cached.st_mode != mode:
+                       os.chmod(filename, mode | stat_cached.st_mode)
+       except OSError, oe:
+               if oe.errno == errno.EPERM:
+                       raise OperationNotPermitted(oe)
+               elif oe.errno == errno.ENOENT:
+                       raise FileNotFound(oe)
+               else:
+                       raise oe
 
 def apply_stat_permissions(filename, newstat, stat_cached=None):
        """A wrapper around apply_secpass_permissions that gets
@@ -530,12 +538,10 @@ class atomic_ofstream(file):
                                if not self._aborted:
                                        try:
                                                apply_stat_permissions(self.name, os.stat(self._real_name))
-                                       except OSError, oe:
-                                               import errno
-                                               if oe.errno in (errno.ENOENT,errno.EPERM):
-                                                       pass
-                                               else:
-                                                       raise oe
+                                       except OperationNotPermitted:
+                                               pass
+                                       except FileNotFound:
+                                               pass
                                        os.rename(self.name, self._real_name)
                        finally:
                                # Make sure we cleanup the temp file