def _get_valid_mem_map_dirs()

in azure_functions_worker/bindings/shared_memory_data_transfer/file_accessor_unix.py [0:0]


    def _get_valid_mem_map_dirs(self) -> List[str]:
        """
        From the configured list of allowed directories where memory maps can be
        stored, return all those that either already existed or were created
        successfully for use.
        Returns list of directories, in decreasing order of preference, where
        memory maps can be created.
        """
        allowed_dirs = self._get_allowed_mem_map_dirs()
        # Iterate over all the possible directories where the memory map could
        # be created and try to create each of them if they don't exist already.
        valid_dirs = []
        for temp_dir in allowed_dirs:
            dir_path = os.path.join(temp_dir, consts.UNIX_TEMP_DIR_SUFFIX)
            if os.path.exists(dir_path):
                # A valid directory already exists
                valid_dirs.append(dir_path)
                logger.debug('Found directory %s to store memory maps',
                             dir_path)
            else:
                try:
                    os.makedirs(dir_path)
                    valid_dirs.append(dir_path)
                except Exception as e:
                    # We keep trying to check/create others
                    logger.warning('Cannot create directory %s to '
                                   'store memory maps - %s', dir_path, e,
                                   exc_info=True)
        if len(valid_dirs) == 0:
            logger.error('No valid directory for memory maps in %s',
                         allowed_dirs)
        return valid_dirs