def METHOD_NAME(var, directory):
    messages = []
    if directory:
        if not os.path.isdir(directory):
            messages.append(
                Error(exists_message.format(var), exists_hint.format(directory)),
            )
        else:
            test_file = os.path.join(
                directory,
                f"__paperless_write_test_{os.getpid()}__",
            )
            try:
                with open(test_file, "w"):
                    pass
            except PermissionError:
                dir_stat = os.stat(directory)
                dir_mode = stat.filemode(dir_stat.st_mode)
                dir_owner = pwd.getpwuid(dir_stat.st_uid).pw_name
                dir_group = grp.getgrgid(dir_stat.st_gid).gr_name
                messages.append(
                    Error(
                        writeable_message.format(var),
                        writeable_hint.format(
                            f"\n{dir_mode} {dir_owner} {dir_group} {directory}\n",
                        ),
                    ),
                )
            finally:
                if os.path.isfile(test_file):
                    os.remove(test_file)
    return messages