'Return the directory in HDFS, creating it if necessary.'

def _create_dir(self, path, perms=None):

    try:
        statbuf = self.fs.stats(path)
        if (not statbuf.isDir):
            msg = (_('Path    is    not    a    directory:    %s.') % (path,))
            LOG.error(msg)
            raise Exception(msg)
    except IOError as ex:
        if (ex.errno != errno.ENOENT):
            msg = (_("Error    accessing    directory    '%s':    %s.") % (path, ex))
            LOG.exception(msg)
            raise IOError(ex.errno, msg)
    if (not self.fs.exists(path)):
        self._do_as(self.user.username, self.fs.mkdir, path, perms)
    if (perms is not None):
        self._do_as(self.user.username, self.fs.chmod, path, perms)
    return path
