diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-10-21 18:38:00 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-10-21 18:38:00 +0000 |
commit | 2e4f9fca17a3b0f76188bed4ad9b9864e8ef67f9 (patch) | |
tree | 384c0b3c7591a530d5c0e32c8da34abba498a161 | |
parent | 548d052ebdf7cfdb5a1e16981f82e13fc9a19725 (diff) | |
download | portage-2e4f9fca17a3b0f76188bed4ad9b9864e8ef67f9.tar.gz portage-2e4f9fca17a3b0f76188bed4ad9b9864e8ef67f9.tar.bz2 portage-2e4f9fca17a3b0f76188bed4ad9b9864e8ef67f9.zip |
Fix NewsManager.getUnreadItems() so that it works properly
for an unprivileged user in readonly mode.
svn path=/main/trunk/; revision=8215
-rw-r--r-- | pym/portage/news.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/pym/portage/news.py b/pym/portage/news.py index cd8386e79..540372e10 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -3,6 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import errno import os import re from portage.const import INCREMENTALS, PROFILE_PATH, NEWS_LIB_PATH @@ -128,22 +129,24 @@ 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: + if os.access(os.path.dirname(unreadfile), os.W_OK): + # TODO: implement shared readonly locks unread_lock = lockfile(unreadfile) - # Set correct permissions on the news-repoid.unread file - apply_permissions(filename=unreadfile, - uid=int(self.config['PORTAGE_INST_UID']), gid=portage_gid, mode=0664) - - if os.path.exists(unreadfile): - unread = open(unreadfile).readlines() - if len(unread): - return len(unread) - except FileNotFound: - pass # unread file may not exist + try: + f = open(unreadfile) + try: + unread = f.readlines() + finally: + f.close() + except EnvironmentError, e: + if e.errno != errno.ENOENT: + raise + del e + return 0 + if len(unread): + return len(unread) finally: if unread_lock: unlockfile(unread_lock) |