Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r10917 - main/trunk/pym/portage
Date: Thu, 03 Jul 2008 22:48:28
Message-Id: E1KEXbC-0000um-HX@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-07-03 22:48:21 +0000 (Thu, 03 Jul 2008)
3 New Revision: 10917
4
5 Modified:
6 main/trunk/pym/portage/__init__.py
7 main/trunk/pym/portage/exception.py
8 main/trunk/pym/portage/locks.py
9 Log:
10 Bug #230469 - Implement non-blocking distlocks for --fetchonly. This adds
11 a "flags" keyword parameter to the portage.locks.lock() function. Default
12 is flags=0. If flags contains os.O_NONBLOCK then lock() will raise
13 portage.exception.TryAgain instead of blocking. This new flags parameter
14 is used to implement non-blocking distlocks in fetch() when fetchonly
15 mode is enabled.
16
17
18 Modified: main/trunk/pym/portage/__init__.py
19 ===================================================================
20 --- main/trunk/pym/portage/__init__.py 2008-07-03 21:53:37 UTC (rev 10916)
21 +++ main/trunk/pym/portage/__init__.py 2008-07-03 22:48:21 UTC (rev 10917)
22 @@ -3512,15 +3512,27 @@
23 from textwrap import wrap
24 waiting_msg = "\n".join(msg_prefix + line \
25 for line in wrap(waiting_msg, 65))
26 +
27 if locks_in_subdir:
28 - file_lock = portage.locks.lockfile(
29 - os.path.join(mysettings["DISTDIR"],
30 - locks_in_subdir, myfile), wantnewlockfile=1,
31 - waiting_msg=waiting_msg)
32 + lock_file = os.path.join(mysettings["DISTDIR"],
33 + locks_in_subdir, myfile)
34 else:
35 - file_lock = portage.locks.lockfile(
36 - myfile_path, wantnewlockfile=1,
37 - waiting_msg=waiting_msg)
38 + lock_file = myfile_path
39 +
40 + lock_kwargs = {}
41 + if fetchonly:
42 + lock_kwargs["flags"] = os.O_NONBLOCK
43 + else:
44 + lock_kwargs["waiting_msg"] = waiting_msg
45 +
46 + try:
47 + file_lock = portage.locks.lockfile(myfile_path,
48 + wantnewlockfile=1, **lock_kwargs)
49 + except portage.exception.TryAgain:
50 + writemsg((">>> File '%s' is already locked by " + \
51 + "another fetcher. Continuing...\n") % myfile,
52 + noiselevel=-1)
53 + continue
54 try:
55 if not listonly:
56
57
58 Modified: main/trunk/pym/portage/exception.py
59 ===================================================================
60 --- main/trunk/pym/portage/exception.py 2008-07-03 21:53:37 UTC (rev 10916)
61 +++ main/trunk/pym/portage/exception.py 2008-07-03 22:48:21 UTC (rev 10917)
62 @@ -57,6 +57,10 @@
63 from errno import EACCES as errno
64 """Permission denied"""
65
66 +class TryAgain(PortageException):
67 + from errno import EAGAIN as errno
68 + """Try again"""
69 +
70 class ReadOnlyFileSystem(PortageException):
71 """Read-only file system"""
72
73
74 Modified: main/trunk/pym/portage/locks.py
75 ===================================================================
76 --- main/trunk/pym/portage/locks.py 2008-07-03 21:53:37 UTC (rev 10916)
77 +++ main/trunk/pym/portage/locks.py 2008-07-03 22:48:21 UTC (rev 10917)
78 @@ -5,7 +5,8 @@
79
80
81 import errno, os, stat, time, types
82 -from portage.exception import InvalidData, DirectoryNotFound, FileNotFound
83 +from portage.exception import DirectoryNotFound, FileNotFound, \
84 + InvalidData, TryAgain
85 from portage.data import portage_gid
86 from portage.util import writemsg
87 from portage.localization import _
88 @@ -17,7 +18,8 @@
89 def unlockdir(mylock):
90 return unlockfile(mylock)
91
92 -def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
93 +def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
94 + waiting_msg=None, flags=0):
95 """Creates all dirs upto, the given dir. Creates a lockfile
96 for the given directory as the file: directoryname+'.portage_lockfile'."""
97 import fcntl
98 @@ -54,7 +56,8 @@
99 except OSError, e:
100 if e[0] == 2: # No such file or directory
101 return lockfile(mypath, wantnewlockfile=wantnewlockfile,
102 - unlinkfile=unlinkfile, waiting_msg=waiting_msg)
103 + unlinkfile=unlinkfile, waiting_msg=waiting_msg,
104 + flags=flags)
105 else:
106 writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n");
107 os.umask(old_mask)
108 @@ -78,6 +81,8 @@
109 raise
110 if e.errno in (errno.EACCES, errno.EAGAIN):
111 # resource temp unavailable; eg, someone beat us to the lock.
112 + if flags & os.O_NONBLOCK:
113 + raise TryAgain(mypath)
114 if waiting_msg is None:
115 if isinstance(mypath, int):
116 print "waiting for lock on fd %i" % myfd
117 @@ -114,7 +119,7 @@
118 writemsg("lockfile recurse\n",1)
119 lockfilename, myfd, unlinkfile, locking_method = lockfile(
120 mypath, wantnewlockfile=wantnewlockfile, unlinkfile=unlinkfile,
121 - waiting_msg=waiting_msg)
122 + waiting_msg=waiting_msg, flags=flags)
123
124 writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
125 return (lockfilename,myfd,unlinkfile,locking_method)
126
127 --
128 gentoo-commits@l.g.o mailing list