Redmine#6331: Skip non-empty directories silently when recursively deleting

The last commit fixes Redmine#6331, by skipping non-empty directories silently when recursively deleting. The rest are only making the code easier to digest.
So what if it is "/etc/mydir", or "/etc/mydir/" or "/etc/mydir/././.". For the OS should be exactly the same. Did some basic testing and behaviour is identical.

But then I searched the commit logs and found out in 4a6fad4993abf03877870c3aa42272444d9511b3 that this is supposedly a fix for a completely separate issue, basedir deletion. However it doesn't seem to affect that behaviour either, unless I'm missing something.