Fixing locking on dir not working in all cases