1 |
There was a race inside fs_template._ensure_dirs which could cause it to |
2 |
raise EEXIST if a concurrent process created the directory after |
3 |
os.path.exists returned False. Fix it by using the util.ensure_dirs |
4 |
function, which already handles EEXIST. |
5 |
|
6 |
X-Gentoo-Bug: 529120 |
7 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=529120 |
8 |
--- |
9 |
pym/portage/cache/fs_template.py | 25 ++++++++++--------------- |
10 |
1 file changed, 10 insertions(+), 15 deletions(-) |
11 |
|
12 |
diff --git a/pym/portage/cache/fs_template.py b/pym/portage/cache/fs_template.py |
13 |
index de4fe4b..fa44abc 100644 |
14 |
--- a/pym/portage/cache/fs_template.py |
15 |
+++ b/pym/portage/cache/fs_template.py |
16 |
@@ -10,7 +10,7 @@ from portage import os |
17 |
from portage.proxy.lazyimport import lazyimport |
18 |
lazyimport(globals(), |
19 |
'portage.exception:PortageException', |
20 |
- 'portage.util:apply_permissions', |
21 |
+ 'portage.util:apply_permissions,ensure_dirs', |
22 |
) |
23 |
del lazyimport |
24 |
|
25 |
@@ -61,20 +61,15 @@ class FsBased(template.database): |
26 |
|
27 |
for dir in path.lstrip(os.path.sep).rstrip(os.path.sep).split(os.path.sep): |
28 |
base = os.path.join(base,dir) |
29 |
- if not os.path.exists(base): |
30 |
- if self._perms != -1: |
31 |
- um = os.umask(0) |
32 |
- try: |
33 |
- perms = self._perms |
34 |
- if perms == -1: |
35 |
- perms = 0 |
36 |
- perms |= 0o755 |
37 |
- os.mkdir(base, perms) |
38 |
- if self._gid != -1: |
39 |
- os.chown(base, -1, self._gid) |
40 |
- finally: |
41 |
- if self._perms != -1: |
42 |
- os.umask(um) |
43 |
+ if ensure_dirs(base): |
44 |
+ # We only call apply_permissions if ensure_dirs created |
45 |
+ # a new directory, so as not to interfere with |
46 |
+ # permissions of existing directories. |
47 |
+ mode = self._perms |
48 |
+ if mode == -1: |
49 |
+ mode = 0 |
50 |
+ mode |= 0o755 |
51 |
+ apply_permissions(base, mode=mode, gid=self._gid) |
52 |
|
53 |
def _prune_empty_dirs(self): |
54 |
all_dirs = [] |
55 |
-- |
56 |
2.0.4 |