Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
e2dde5bd
Commit
e2dde5bd
authored
Jul 20, 2018
by
Paul Ganssle
Committed by
GitHub
Jul 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1418 from pganssle/egg_race_condition
Egg race condition
parents
5f510913
67f190ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
changelog.d/1418.change.rst
changelog.d/1418.change.rst
+1
-0
pkg_resources/__init__.py
pkg_resources/__init__.py
+9
-1
pkg_resources/tests/test_pkg_resources.py
pkg_resources/tests/test_pkg_resources.py
+32
-1
No files found.
changelog.d/1418.change.rst
0 → 100644
View file @
e2dde5bd
Solved race in when creating egg cache directories.
pkg_resources/__init__.py
View file @
e2dde5bd
...
...
@@ -47,6 +47,11 @@ except ImportError:
# Python 3.2 compatibility
import
imp
as
_imp
try
:
FileExistsError
except
NameError
:
FileExistsError
=
OSError
from
pkg_resources.extern
import
six
from
pkg_resources.extern.six.moves
import
urllib
,
map
,
filter
...
...
@@ -3030,7 +3035,10 @@ def _bypass_ensure_directory(path):
dirname, filename = split(path)
if dirname and filename and not isdir(dirname):
_bypass_ensure_directory(dirname)
mkdir(dirname, 0o755)
try:
mkdir(dirname, 0o755)
except FileExistsError:
pass
def split_sections(s):
...
...
pkg_resources/tests/test_pkg_resources.py
View file @
e2dde5bd
...
...
@@ -12,6 +12,11 @@ import stat
import
distutils.dist
import
distutils.command.install_egg_info
try
:
from
unittest
import
mock
except
ImportError
:
import
mock
from
pkg_resources.extern.six.moves
import
map
from
pkg_resources.extern.six
import
text_type
,
string_types
...
...
@@ -138,8 +143,34 @@ class TestResourceManager:
message
=
"Unexpected type from get_cache_path: "
+
type_
assert
isinstance
(
path
,
string_types
),
message
def
test_get_cache_path_race
(
self
,
tmpdir
):
# Patch to os.path.isdir to create a race condition
def
patched_isdir
(
dirname
,
unpatched_isdir
=
pkg_resources
.
isdir
):
patched_isdir
.
dirnames
.
append
(
dirname
)
was_dir
=
unpatched_isdir
(
dirname
)
if
not
was_dir
:
os
.
makedirs
(
dirname
)
return
was_dir
patched_isdir
.
dirnames
=
[]
# Get a cache path with a "race condition"
mgr
=
pkg_resources
.
ResourceManager
()
mgr
.
set_extraction_path
(
str
(
tmpdir
))
archive_name
=
os
.
sep
.
join
((
'foo'
,
'bar'
,
'baz'
))
with
mock
.
patch
.
object
(
pkg_resources
,
'isdir'
,
new
=
patched_isdir
):
mgr
.
get_cache_path
(
archive_name
)
# Because this test relies on the implementation details of this
# function, these assertions are a sentinel to ensure that the
# test suite will not fail silently if the implementation changes.
called_dirnames
=
patched_isdir
.
dirnames
assert
len
(
called_dirnames
)
==
2
assert
called_dirnames
[
0
].
split
(
os
.
sep
)[
-
2
:]
==
[
'foo'
,
'bar'
]
assert
called_dirnames
[
1
].
split
(
os
.
sep
)[
-
1
:]
==
[
'foo'
]
class
TestIndependence
:
"""
Tests to ensure that pkg_resources runs independently from setuptools.
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment