fix empty directories being left behind in some rare cases