diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-01-16 06:39:46 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-01-16 06:39:46 +0000 |
commit | a98e5767f3fad6162f9b01e3974ccaf211703c89 (patch) | |
tree | 27c64a267cda74ffdbe45266f65914cd4c5acbbf | |
parent | 32b12d5d73812819dddbe1345b23048c97113478 (diff) | |
download | portage-a98e5767f3fad6162f9b01e3974ccaf211703c89.tar.gz portage-a98e5767f3fad6162f9b01e3974ccaf211703c89.tar.bz2 portage-a98e5767f3fad6162f9b01e3974ccaf211703c89.zip |
Bug #255101 - Fix 'Permission denied' error handling in
NewsManager.getUnreadItems(). If there's no permission to lock the unread
file, skip the lock and try to read the file anyway.
svn path=/main/trunk/; revision=12521
-rw-r--r-- | pym/portage/locks.py | 27 | ||||
-rw-r--r-- | pym/portage/news.py | 2 |
2 files changed, 19 insertions, 10 deletions
diff --git a/pym/portage/locks.py b/pym/portage/locks.py index f557d8096..be7cdf07d 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -9,7 +9,7 @@ __all__ = ["lockdir", "unlockdir", "lockfile", "unlockfile", \ import errno, os, stat, time, types from portage.exception import DirectoryNotFound, FileNotFound, \ - InvalidData, TryAgain + InvalidData, TryAgain, OperationNotPermitted, PermissionDenied from portage.data import portage_gid from portage.output import EOutput from portage.util import writemsg @@ -55,22 +55,31 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, if type(mypath) == types.StringType: if not os.path.exists(os.path.dirname(mypath)): raise DirectoryNotFound(os.path.dirname(mypath)) - if not os.path.exists(lockfilename): - old_mask=os.umask(000) - myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660) + old_mask = os.umask(000) + try: + try: + myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR, 0660) + except OSError, e: + func_call = "open('%s')" % lockfilename + if e.errno == OperationNotPermitted.errno: + raise OperationNotPermitted(func_call) + elif e.errno == PermissionDenied.errno: + raise PermissionDenied(func_call) + else: + raise try: if os.stat(lockfilename).st_gid != portage_gid: - os.chown(lockfilename,os.getuid(),portage_gid) + os.chown(lockfilename, os.getuid(), portage_gid) except OSError, e: - if e[0] == 2: # No such file or directory + if e.errno == errno.ENOENT: # No such file or directory return lockfile(mypath, wantnewlockfile=wantnewlockfile, unlinkfile=unlinkfile, waiting_msg=waiting_msg, flags=flags) else: - writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n"); + writemsg("Cannot chown a lockfile. This could " + \ + "cause inconvenience later.\n") + finally: os.umask(old_mask) - else: - myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660) elif type(mypath) == types.IntType: myfd = mypath diff --git a/pym/portage/news.py b/pym/portage/news.py index 90dd3a065..b20fd422e 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -157,7 +157,7 @@ class NewsManager(object): try: unread_lock = lockfile(unread_filename, wantnewlockfile=1) except (InvalidLocation, OperationNotPermitted, PermissionDenied): - return 0 + pass try: try: return len(grabfile(unread_filename)) |