* [gentoo-portage-dev] [PATCH] fs_template._ensure_dirs: handle EEXIST (529120)
@ 2014-11-13 19:44 Zac Medico
2014-11-14 8:45 ` Alexander Berntsen
0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2014-11-13 19:44 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
There was a race inside fs_template._ensure_dirs which could cause it to
raise EEXIST if a concurrent process created the directory after
os.path.exists returned False. Fix it by using the util.ensure_dirs
function, which already handles EEXIST.
X-Gentoo-Bug: 529120
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=529120
---
pym/portage/cache/fs_template.py | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/pym/portage/cache/fs_template.py b/pym/portage/cache/fs_template.py
index de4fe4b..fa44abc 100644
--- a/pym/portage/cache/fs_template.py
+++ b/pym/portage/cache/fs_template.py
@@ -10,7 +10,7 @@ from portage import os
from portage.proxy.lazyimport import lazyimport
lazyimport(globals(),
'portage.exception:PortageException',
- 'portage.util:apply_permissions',
+ 'portage.util:apply_permissions,ensure_dirs',
)
del lazyimport
@@ -61,20 +61,15 @@ class FsBased(template.database):
for dir in path.lstrip(os.path.sep).rstrip(os.path.sep).split(os.path.sep):
base = os.path.join(base,dir)
- if not os.path.exists(base):
- if self._perms != -1:
- um = os.umask(0)
- try:
- perms = self._perms
- if perms == -1:
- perms = 0
- perms |= 0o755
- os.mkdir(base, perms)
- if self._gid != -1:
- os.chown(base, -1, self._gid)
- finally:
- if self._perms != -1:
- os.umask(um)
+ if ensure_dirs(base):
+ # We only call apply_permissions if ensure_dirs created
+ # a new directory, so as not to interfere with
+ # permissions of existing directories.
+ mode = self._perms
+ if mode == -1:
+ mode = 0
+ mode |= 0o755
+ apply_permissions(base, mode=mode, gid=self._gid)
def _prune_empty_dirs(self):
all_dirs = []
--
2.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] fs_template._ensure_dirs: handle EEXIST (529120)
2014-11-13 19:44 [gentoo-portage-dev] [PATCH] fs_template._ensure_dirs: handle EEXIST (529120) Zac Medico
@ 2014-11-14 8:45 ` Alexander Berntsen
0 siblings, 0 replies; 2+ messages in thread
From: Alexander Berntsen @ 2014-11-14 8:45 UTC (permalink / raw
To: gentoo-portage-dev
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
LGTM. Go ahead & merge.
- --
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlRlwSAACgkQRtClrXBQc7We7AD+Mu0N+qkL+KDjmVgFa/AZ4VX4
+D2pxqPMHwzAmdqjZ2EBAIMAsk1GFRRo6OvPWKmv/fJv9QATCA6e8ZZMcs/wZrjs
=K/rk
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-14 8:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 19:44 [gentoo-portage-dev] [PATCH] fs_template._ensure_dirs: handle EEXIST (529120) Zac Medico
2014-11-14 8:45 ` Alexander Berntsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox