succeeds if the target directory exists after an mkdir() race with
another process.
/build/
/dist/
/*.egg-info
+/tmp
import os
import re
import subprocess
+import errno
def clear_tmpdir(path=None):
"""
return path
def mkdir_dash_p(path):
- if not os.path.exists(path):
- os.makedirs(path)
+ if not os.path.isdir(path):
+ try:
+ os.makedirs(path)
+ except OSError as e:
+ if e.errno == errno.EEXIST and os.path.isdir(path):
+ # It is not an error if someone else creates the
+ # directory between our exists() and makedirs() calls.
+ pass
+ else:
+ raise
def stream_extract(stream, path, files=[], decompress=True):
"""Retrieve a stream from Keep and extract it to a local
--- /dev/null
+import unittest
+import os
+import arvados.util
+
+class MkdirDashPTest(unittest.TestCase):
+ def setUp(self):
+ try:
+ os.path.mkdir('./tmp')
+ except:
+ pass
+ def tearDown(self):
+ try:
+ os.unlink('./tmp/bar')
+ os.rmdir('./tmp/foo')
+ os.rmdir('./tmp')
+ except:
+ pass
+ def runTest(self):
+ arvados.util.mkdir_dash_p('./tmp/foo')
+ with open('./tmp/bar', 'wb') as f:
+ f.write('bar')
+ self.assertRaises(OSError, arvados.util.mkdir_dash_p, './tmp/bar')