def set_permissions_from_data_directory(self, data_dir: str) -> None:
        """Set new permissions based on provided *data_dir*.

        :param data_dir: reference to PGDATA to calculate permissions from.
        """
        try:
            st = os.stat(data_dir)
            if (st.st_mode & self.__PG_DIR_MODE_GROUP) == self.__PG_DIR_MODE_GROUP:
                self.__set_group_permissions()
            else:
                self.__set_owner_permissions()
        except Exception as e:
            logger.error('Can not check permissions on %s: %r', data_dir, e)
        else:
            self.__set_umask()
Set new permissions based on provided *data_dir*.

        :param data_dir: reference to PGDATA to calculate permissions from.
        
patroni/file_perm.py