fix rare bug in which makedirs has a duplicate dir