fix race condition
do race-able check before making directory, to reduce # of directory creation attempts
use errno field to check error number, instead of parsing string
changed hardcoded 17 to errno.EEXIST
Merge pull request #1157 from goodfeli/master

fix race condition