diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-07-03 22:48:21 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-07-03 22:48:21 +0000 |
commit | 354e3edebebbdb23007db0e4af2dd294fecd570b (patch) | |
tree | 2301b0e889a89c699f1c092160142b243f1b5df0 /pym/portage/locks.py | |
parent | Fix typo. (diff) | |
download | portage-354e3edebebbdb23007db0e4af2dd294fecd570b.tar.gz portage-354e3edebebbdb23007db0e4af2dd294fecd570b.tar.bz2 portage-354e3edebebbdb23007db0e4af2dd294fecd570b.zip |
Bug #230469 - Implement non-blocking distlocks for --fetchonly. This adds
a "flags" keyword parameter to the portage.locks.lock() function. Default
is flags=0. If flags contains os.O_NONBLOCK then lock() will raise
portage.exception.TryAgain instead of blocking. This new flags parameter
is used to implement non-blocking distlocks in fetch() when fetchonly
mode is enabled.
svn path=/main/trunk/; revision=10917
Diffstat (limited to 'pym/portage/locks.py')
-rw-r--r-- | pym/portage/locks.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 004108eb7..000cd3495 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -5,7 +5,8 @@ import errno, os, stat, time, types -from portage.exception import InvalidData, DirectoryNotFound, FileNotFound +from portage.exception import DirectoryNotFound, FileNotFound, \ + InvalidData, TryAgain from portage.data import portage_gid from portage.util import writemsg from portage.localization import _ @@ -17,7 +18,8 @@ def lockdir(mydir): def unlockdir(mylock): return unlockfile(mylock) -def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): +def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, + waiting_msg=None, flags=0): """Creates all dirs upto, the given dir. Creates a lockfile for the given directory as the file: directoryname+'.portage_lockfile'.""" import fcntl @@ -54,7 +56,8 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): except OSError, e: if e[0] == 2: # No such file or directory return lockfile(mypath, wantnewlockfile=wantnewlockfile, - unlinkfile=unlinkfile, waiting_msg=waiting_msg) + unlinkfile=unlinkfile, waiting_msg=waiting_msg, + flags=flags) else: writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n"); os.umask(old_mask) @@ -78,6 +81,8 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): raise if e.errno in (errno.EACCES, errno.EAGAIN): # resource temp unavailable; eg, someone beat us to the lock. + if flags & os.O_NONBLOCK: + raise TryAgain(mypath) if waiting_msg is None: if isinstance(mypath, int): print "waiting for lock on fd %i" % myfd @@ -114,7 +119,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): writemsg("lockfile recurse\n",1) lockfilename, myfd, unlinkfile, locking_method = lockfile( mypath, wantnewlockfile=wantnewlockfile, unlinkfile=unlinkfile, - waiting_msg=waiting_msg) + waiting_msg=waiting_msg, flags=flags) writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1) return (lockfilename,myfd,unlinkfile,locking_method) |