from textwrap import wrap
waiting_msg = "\n".join(msg_prefix + line \
for line in wrap(waiting_msg, 65))
+
if locks_in_subdir:
- file_lock = portage.locks.lockfile(
- os.path.join(mysettings["DISTDIR"],
- locks_in_subdir, myfile), wantnewlockfile=1,
- waiting_msg=waiting_msg)
+ lock_file = os.path.join(mysettings["DISTDIR"],
+ locks_in_subdir, myfile)
+ else:
+ lock_file = myfile_path
+
+ lock_kwargs = {}
+ if fetchonly:
+ lock_kwargs["flags"] = os.O_NONBLOCK
else:
- file_lock = portage.locks.lockfile(
- myfile_path, wantnewlockfile=1,
- waiting_msg=waiting_msg)
+ lock_kwargs["waiting_msg"] = waiting_msg
+
+ try:
+ file_lock = portage.locks.lockfile(myfile_path,
+ wantnewlockfile=1, **lock_kwargs)
+ except portage.exception.TryAgain:
+ writemsg((">>> File '%s' is already locked by " + \
+ "another fetcher. Continuing...\n") % myfile,
+ noiselevel=-1)
+ continue
try:
if not listonly:
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 _
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
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)
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
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)