[ARVADOS] updated: 36cb102dca2aba54c01b4a4d08bb7c2a2d4ad337
git at public.curoverse.com
git at public.curoverse.com
Mon Feb 3 11:22:41 EST 2014
Summary of changes:
sdk/python/.gitignore | 1 +
sdk/python/arvados/util.py | 13 +++++++++++--
sdk/python/test_util.py | 22 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 sdk/python/test_util.py
via 36cb102dca2aba54c01b4a4d08bb7c2a2d4ad337 (commit)
from 4d779096453fd54437df2fdafd682b550e24861f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 36cb102dca2aba54c01b4a4d08bb7c2a2d4ad337
Author: Tom Clegg <tom at curoverse.com>
Date: Mon Feb 3 08:21:05 2014 -0800
Ensure util.mkdir_dash_p() fails if its target is a non-directory, and
succeeds if the target directory exists after an mkdir() race with
another process.
diff --git a/sdk/python/.gitignore b/sdk/python/.gitignore
index 2d2799c..7f9c17b 100644
--- a/sdk/python/.gitignore
+++ b/sdk/python/.gitignore
@@ -1,3 +1,4 @@
/build/
/dist/
/*.egg-info
+/tmp
diff --git a/sdk/python/arvados/util.py b/sdk/python/arvados/util.py
index 4e0d6f0..552fbbe 100644
--- a/sdk/python/arvados/util.py
+++ b/sdk/python/arvados/util.py
@@ -3,6 +3,7 @@ import hashlib
import os
import re
import subprocess
+import errno
def clear_tmpdir(path=None):
"""
@@ -242,8 +243,16 @@ def collection_extract(collection, path, files=[], decompress=True):
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
diff --git a/sdk/python/test_util.py b/sdk/python/test_util.py
new file mode 100644
index 0000000..f9e5d8c
--- /dev/null
+++ b/sdk/python/test_util.py
@@ -0,0 +1,22 @@
+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')
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list