Improved check_perms() to work with a directory, to have better