New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent race condition in os.makedirs #42197
Comments
makedirs check if a directory exists, and call mkdir to create it. In To prevent this rare race condition, use try: expect: to create the |
Logged In: YES See bug bpo-1223238. |
Logged In: YES I can't find such bug or patch. |
Logged In: YES http://sourceforge.net/tracker/index.php?func=detail&aid=1223238&group_id=5470&atid=105470 |
Logged In: YES Here is another patch, using simpler design, maybe for 2.5? The attached patch will try once to create each leaf in the path, ignoring This should work for most cases. If one run application that can delete its |
Logged In: YES Hi, >>> os.getcwd()
'C:\\Temp\\makedirs'
>>> os.listdir('.')
['makedirs.py', 'makedirs.pyc', 'test.py']
>>> makedirs.makedirs('c:/temp/makedirs/a/b')
>>> os.listdir('.')
['makedirs.py', 'makedirs.pyc', 'temp', 'test.py'] It will create the following path: Also I ran it through the test suite (lib\test\test_os.py) ====================================================================== Traceback (most recent call last):
File "test_os.py", line 327, in test_makedir
self.failUnlessRaises(OSError, os.makedirs, os.curdir)
AssertionError: OSError not raised I haven't looked into *why* this happens - I'll dig a bit HTH, |
Logged In: YES The 2.5 code is only a proof of concept, don't use it as is :-) All the directories are handled in the same way - ignore OSError for I'll get 2.5 development code and submit a real working patch. |
Logged In: YES I deleted both patches as they are both wrong: The patch against 2.4.1 will not raise OSError when trying to create existing The simpler code for 2.5 will not work because os.path.normpath is not safe |
Logged In: YES Please review this new patch, tested with current 2.5 code. I factored duplicate code in makedirs and removedirs into private _splits I also simplified the test code for makedirs, and added more test cases. |
Logged In: YES Sorry, here is the patch. |
Something similar has been committed as patch bpo-1608267. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: