BUG: Fix OSError when creating sids that share dir

Fix a bug where creating a sid bcolz file when the containing directory
was already occupied by a sid caused an OSError on attempt of creating
the directory because it already existed.

e.g. if there were two sids, `1` and `2`. The paths would be
`00/00/000001.bcolz` and `00/00/000002.bcolz` which share the same
directory `00/00`.

Fixed by checking for directory existence before calling `makedirs`.

Add test coverage which exercises writing of sids that are siblings in
the sid directory structure.
This commit is contained in:
Eddie Hebert
2016-01-25 10:37:50 -05:00
parent 603a345e2d
commit 984e934e83
2 changed files with 95 additions and 3 deletions
+7 -3
View File
@@ -300,9 +300,13 @@ class BcolzMinuteBarWriter(object):
path : string
The path to rootdir of the new ctable.
"""
# Only create the subdir on container creation.
sid_dirname = os.path.dirname(path)
os.makedirs(sid_dirname)
# Only create the containing subdir on creation.
# This is not to be confused with the `.bcolz` directory, but is the
# directory up one level from the `.bcolz` directories.
sid_containing_dirname = os.path.dirname(path)
if not os.path.exists(sid_containing_dirname):
# Other sids may have already created the containing directory.
os.makedirs(sid_containing_dirname)
initial_array = np.empty(0, np.uint32)
table = ctable(
rootdir=path,