For bug #138840, show a more informative message when waiting for a distfiles lock...
authorZac Medico <zmedico@gentoo.org>
Sat, 3 Mar 2007 09:49:56 +0000 (09:49 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 3 Mar 2007 09:49:56 +0000 (09:49 -0000)
svn path=/main/branches/2.1.2/; revision=6144

pym/portage.py
pym/portage_locks.py

index e340754376c92a1144b6dd96328d11e6866caa86..99a2aa9e82fca7e6c539b8f2e8f73346d95a0e10 100644 (file)
@@ -2438,10 +2438,19 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                        writemsg_stdout("\n", noiselevel=-1)
                else:
                        if use_locks and can_fetch:
+                               waiting_msg = None
+                               if "parallel-fetch" in features:
+                                       waiting_msg = ("Downloading '%s'... " + \
+                                               "see /var/log/emerge-fetch.log for details.") % myfile
                                if locks_in_subdir:
-                                       file_lock = portage_locks.lockfile(mysettings["DISTDIR"]+"/"+locks_in_subdir+"/"+myfile,wantnewlockfile=1)
+                                       file_lock = portage_locks.lockfile(
+                                               os.path.join(mysettings["DISTDIR"],
+                                               locks_in_subdir, myfile), wantnewlockfile=1,
+                                               waiting_msg=waiting_msg)
                                else:
-                                       file_lock = portage_locks.lockfile(mysettings["DISTDIR"]+"/"+myfile,wantnewlockfile=1)
+                                       file_lock = portage_locks.lockfile(
+                                               myfile_path, wantnewlockfile=1,
+                                               waiting_msg=waiting_msg)
                try:
                        if not listonly:
                                if fsmirrors and not os.path.exists(myfile_path):
index 28042e2fb712e00a776ed8c2c430c852001791a9..77044cacf250494e6e00d2608848464352b67f03 100644 (file)
@@ -4,10 +4,14 @@
 # $Id$
 
 
-import errno, os, stat, time, types
-from portage_exception import InvalidData, DirectoryNotFound, FileNotFound
-from portage_data import portage_gid
-from portage_util import writemsg
+import errno
+import os
+import stat
+import time
+import types
+import portage_exception
+import portage_util
+import portage_data
 from portage_localization import _
 
 HARDLINK_FD = -2
@@ -17,13 +21,13 @@ def lockdir(mydir):
 def unlockdir(mylock):
        return unlockfile(mylock)
 
-def lockfile(mypath,wantnewlockfile=0,unlinkfile=0):
+def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
        """Creates all dirs upto, the given dir. Creates a lockfile
        for the given directory as the file: directoryname+'.portage_lockfile'."""
        import fcntl
 
        if not mypath:
-               raise InvalidData, "Empty path given"
+               raise portage_exception.InvalidData, "Empty path given"
 
        if type(mypath) == types.StringType and mypath[-1] == '/':
                mypath = mypath[:-1]
@@ -44,18 +48,18 @@ 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)
+                       raise portage_exception.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)
                        try:
-                               if os.stat(lockfilename).st_gid != portage_gid:
-                                       os.chown(lockfilename,os.getuid(),portage_gid)
+                               if os.stat(lockfilename).st_gid != portage_data.portage_gid:
+                                       os.chown(lockfilename,os.getuid(),portage_data.portage_gid)
                        except OSError, e:
                                if e[0] == 2: # No such file or directory
                                        return lockfile(mypath,wantnewlockfile,unlinkfile)
                                else:
-                                       writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n");
+                                       portage_util.writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n");
                        os.umask(old_mask)
                else:
                        myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660)
@@ -76,10 +80,13 @@ def lockfile(mypath,wantnewlockfile=0,unlinkfile=0):
                        raise
                if e.errno == errno.EAGAIN:
                        # resource temp unavailable; eg, someone beat us to the lock.
-                       if type(mypath) == types.IntType:
-                               print "waiting for lock on fd %i" % myfd
-                       else:
-                               print "waiting for lock on %s" % lockfilename
+                       if waiting_msg is None:
+                               if isinstance(mypath, int):
+                                       print "waiting for lock on fd %i" % myfd
+                               else:
+                                       print "waiting for lock on %s" % lockfilename
+                       elif waiting_msg:
+                               print waiting_msg
                        # try for the exclusive lock now.
                        fcntl.lockf(myfd,fcntl.LOCK_EX)
                elif e.errno == errno.ENOLCK:
@@ -106,10 +113,10 @@ def lockfile(mypath,wantnewlockfile=0,unlinkfile=0):
                myfd != HARDLINK_FD and os.fstat(myfd).st_nlink == 0:
                # The file was deleted on us... Keep trying to make one...
                os.close(myfd)
-               writemsg("lockfile recurse\n",1)
+               portage_util.writemsg("lockfile recurse\n",1)
                lockfilename,myfd,unlinkfile,locking_method = lockfile(mypath,wantnewlockfile,unlinkfile)
 
-       writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
+       portage_util.writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
        return (lockfilename,myfd,unlinkfile,locking_method)
 
 def unlockfile(mytuple):
@@ -122,7 +129,7 @@ def unlockfile(mytuple):
        elif len(mytuple) == 4:
                lockfilename,myfd,unlinkfile,locking_method = mytuple
        else:
-               raise InvalidData
+               raise
 
        if(myfd == HARDLINK_FD):
                unhardlink_lockfile(lockfilename)
@@ -130,7 +137,7 @@ def unlockfile(mytuple):
        
        # myfd may be None here due to myfd = mypath in lockfile()
        if type(lockfilename) == types.StringType and not os.path.exists(lockfilename):
-               writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
+               portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
                if myfd is not None:
                        os.close(myfd)
                return False
@@ -156,18 +163,18 @@ def unlockfile(mytuple):
                        locking_method(myfd,fcntl.LOCK_EX|fcntl.LOCK_NB)
                        # We won the lock, so there isn't competition for it.
                        # We can safely delete the file.
-                       writemsg("Got the lockfile...\n",1)
+                       portage_util.writemsg("Got the lockfile...\n",1)
                        if os.fstat(myfd).st_nlink == 1:
                                os.unlink(lockfilename)
-                               writemsg("Unlinked lockfile...\n",1)
+                               portage_util.writemsg("Unlinked lockfile...\n",1)
                                locking_method(myfd,fcntl.LOCK_UN)
                        else:
-                               writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
+                               portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
                                os.close(myfd)
                                return False
        except Exception, e:
-               writemsg("Failed to get lock... someone took it.\n",1)
-               writemsg(str(e)+"\n",1)
+               portage_util.writemsg("Failed to get lock... someone took it.\n",1)
+               portage_util.writemsg(str(e)+"\n",1)
 
        # why test lockfilename?  because we may have been handed an
        # fd originally, and the caller might not like having their
@@ -208,7 +215,7 @@ def hardlink_lockfile(lockfilename, max_wait=14400):
                os.close(myfd)
        
                if not os.path.exists(myhardlock):
-                       raise FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
+                       raise portage_exception.FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
 
                try:
                        res = os.link(myhardlock, lockfilename)
@@ -222,7 +229,7 @@ def hardlink_lockfile(lockfilename, max_wait=14400):
                        return True
 
                if reported_waiting:
-                       writemsg(".")
+                       portage_util.writemsg(".")
                else:
                        reported_waiting = True
                        print