Fixed permissions check to include directories