Title: race condition in pathlib mkdir with flags parents=True
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: arigo, berker.peksag, whitespacer
Priority: normal Keywords: patch

Created on 2017-03-02 13:53 by whitespacer, last changed 2017-03-18 16:53 by berker.peksag.

File name Uploaded Description Edit
x1.diff arigo, 2017-03-07 06:39 review
Messages (2)
msg288801 - (view) Author: whitespacer (whitespacer) Date: 2017-03-02 13:53
When pathlib mkdir is called with parents=True and some parent doesn't exists it recursively calls self.parent.mkdir(parents=True) after catching OSError. However after catching of OSError and before call to self.parent.mkdir(parents=True) somebody else can create parent dir, which will lead to FileExistsError exception.
msg289155 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2017-03-07 06:39
A different bug in the same code: if someone creates the directory itself between the two calls to ``self._accessor.mkdir(self, mode)``, then the function will fail with an exception even if ``exist_ok=True``.

Attached is a patch that fixes both cases.
Date User Action Args
2017-03-18 16:53:10berker.peksagsetnosy: + berker.peksag

components: + Library (Lib)
stage: patch review
2017-03-07 06:39:04arigosetfiles: + x1.diff

nosy: + arigo
messages: + msg289155

keywords: + patch
2017-03-02 13:53:33whitespacercreate