fix race condition in mkdir

fixes issue reported by William Stein on the mailing list