Skip to content

avoid race between `os.path.exists` and `os.makedirs`

When building in parallel two instances of extract_cmake_data.py can be run and race between os.path.exists and os.makedirs: in both processes os.path.exists returns False and both try to call os.makedirs, but only one process can succeed. The other will get an error:

Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/cmake/scripts/extract_cmake_data.py", line 104, in <module>
    read_module()
  File "/<<PKGBUILDDIR>>/cmake/scripts/extract_cmake_data.py", line 34, in read_module
    os.makedirs(modpath)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/<<PKGBUILDDIR>>/build/doc/buildsystem/modules'

This change ignores the os.makedirs error raised when the target directory already exists. As a side-effect, the os.path.exists check can also be dropped.

Merge request reports

Loading