Fixed directory size calculation routine

closedir() now is invoked only if DIR* was actually opened.
Also return early from calculation cycle if an error occurs.