From 548d052ebdf7cfdb5a1e16981f82e13fc9a19725 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 21 Oct 2007 18:07:15 +0000 Subject: [PATCH] Bug #196427 - Prevent various news related tracebacks from occuring when running emerge as an unprivileged user in --pretend mode. svn path=/main/trunk/; revision=8214 --- pym/portage/exception.py | 1 + pym/portage/news.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pym/portage/exception.py b/pym/portage/exception.py index 7802b8016..d91584b73 100644 --- a/pym/portage/exception.py +++ b/pym/portage/exception.py @@ -50,6 +50,7 @@ class DirectoryNotFound(InvalidLocation): """A directory was not found when it was expected to exist""" class OperationNotPermitted(PortageException): + from errno import EPERM as errno """An operation was not permitted operating system""" class PermissionDenied(PortageException): diff --git a/pym/portage/news.py b/pym/portage/news.py index b9326c94d..cd8386e79 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -9,7 +9,7 @@ from portage.const import INCREMENTALS, PROFILE_PATH, NEWS_LIB_PATH from portage.util import ensure_dirs, apply_permissions, normalize_path, grabfile, write_atomic from portage.data import portage_gid from portage.locks import lockfile, unlockfile, lockdir, unlockdir -from portage.exception import FileNotFound +from portage.exception import FileNotFound, OperationNotPermitted class NewsManager(object): """ @@ -44,7 +44,11 @@ class NewsManager(object): # Ensure that the unread path exists and is writable. dirmode = 02070 modemask = 02 - ensure_dirs(self.unread_path, mode=dirmode, mask=modemask, gid=portage_gid) + try: + ensure_dirs(self.unread_path, mode=dirmode, + mask=modemask, gid=portage_gid) + except OperationNotPermitted: + pass def updateItems(self, repoid): """ @@ -103,7 +107,7 @@ class NewsManager(object): try: apply_permissions(filename=skipfile, uid=int(self.config["PORTAGE_INST_UID"]), gid=portage_gid, mode=0664) - except OSError, e: + except OperationNotPermitted, e: import errno # skip "permission denied" errors as we're likely running in pretend mode # with reduced priviledges @@ -124,6 +128,9 @@ class NewsManager(object): self.updateItems(repoid) unreadfile = os.path.join(self.unread_path, 'news-%s.unread' % repoid) + if not os.access(os.path.dirname(unreadfile), os.W_OK): + return 0 + unread_lock = None try: try: unread_lock = lockfile(unreadfile) -- 2.26.2