summaryrefslogtreecommitdiffstats
path: root/pym/portage_util.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-03-14 00:38:24 +0000
committerZac Medico <zmedico@gentoo.org>2006-03-14 00:38:24 +0000
commita9fea52d582034973feaf7fe77a5730ab0ab4849 (patch)
treed632a613c609ef7931c088ddcf4eb12ce02ee90d /pym/portage_util.py
parent556a7562150d7d398b08459f45b98ec961541c6b (diff)
downloadportage-a9fea52d582034973feaf7fe77a5730ab0ab4849.tar.gz
portage-a9fea52d582034973feaf7fe77a5730ab0ab4849.tar.bz2
portage-a9fea52d582034973feaf7fe77a5730ab0ab4849.zip
Add a new OperationNotPermitted exception and use it to wrap apply_permissions exceptions.
svn path=/main/trunk/; revision=2871
Diffstat (limited to 'pym/portage_util.py')
-rw-r--r--pym/portage_util.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 5b8d87d55..205db9b36 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -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