1 |
commit: 02922cb3a7eb72e9bf4cec9e30b35aa4adaa51c8 |
2 |
Author: Zac Medico <zachary.medico <AT> sony <DOT> com> |
3 |
AuthorDate: Tue Feb 19 23:59:35 2019 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 20 00:38:09 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=02922cb3 |
7 |
|
8 |
lockfile: use loop instead of recursion |
9 |
|
10 |
Copyright: Sony Interactive Entertainment Inc. |
11 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
12 |
|
13 |
lib/portage/locks.py | 34 +++++++++++++++++++++++++++++----- |
14 |
1 file changed, 29 insertions(+), 5 deletions(-) |
15 |
|
16 |
diff --git a/lib/portage/locks.py b/lib/portage/locks.py |
17 |
index a23d5cb56..fff27e55e 100644 |
18 |
--- a/lib/portage/locks.py |
19 |
+++ b/lib/portage/locks.py |
20 |
@@ -107,7 +107,34 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, |
21 |
If wantnewlockfile is True then this creates a lockfile in the parent |
22 |
directory as the file: '.' + basename + '.portage_lockfile'. |
23 |
""" |
24 |
+ lock = None |
25 |
+ while lock is None: |
26 |
+ lock = _lockfile_iteration(mypath, wantnewlockfile=wantnewlockfile, |
27 |
+ unlinkfile=unlinkfile, waiting_msg=waiting_msg, flags=flags) |
28 |
+ if lock is None: |
29 |
+ writemsg(_("lockfile removed by previous lock holder, retrying\n"), 1) |
30 |
+ return lock |
31 |
|
32 |
+ |
33 |
+def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False, |
34 |
+ waiting_msg=None, flags=0): |
35 |
+ """ |
36 |
+ Acquire a lock on mypath, without retry. Return None if the lockfile |
37 |
+ was removed by previous lock holder (caller must retry). |
38 |
+ |
39 |
+ @param mypath: lock file path |
40 |
+ @type mypath: str |
41 |
+ @param wantnewlockfile: use a separate new lock file |
42 |
+ @type wantnewlockfile: bool |
43 |
+ @param unlinkfile: remove lock file prior to unlock |
44 |
+ @type unlinkfile: bool |
45 |
+ @param waiting_msg: message to show before blocking |
46 |
+ @type waiting_msg: str |
47 |
+ @param flags: lock flags (only supports os.O_NONBLOCK) |
48 |
+ @type flags: int |
49 |
+ @rtype: bool |
50 |
+ @return: unlockfile tuple on success, None if retry is needed |
51 |
+ """ |
52 |
if not mypath: |
53 |
raise InvalidData(_("Empty path given")) |
54 |
|
55 |
@@ -274,12 +301,9 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, |
56 |
|
57 |
if isinstance(lockfilename, basestring) and \ |
58 |
myfd != HARDLINK_FD and unlinkfile and _lockfile_was_removed(myfd, lockfilename): |
59 |
- # The file was deleted on us... Keep trying to make one... |
60 |
+ # Removed by previous lock holder... Caller will retry... |
61 |
os.close(myfd) |
62 |
- writemsg(_("lockfile recurse\n"), 1) |
63 |
- lockfilename, myfd, unlinkfile, locking_method = lockfile( |
64 |
- mypath, wantnewlockfile=wantnewlockfile, unlinkfile=unlinkfile, |
65 |
- waiting_msg=waiting_msg, flags=flags) |
66 |
+ return None |
67 |
|
68 |
if myfd != HARDLINK_FD: |