ensure_cache_structure Subroutine

public subroutine ensure_cache_structure(cache_dir, success)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: cache_dir
logical, intent(out) :: success

Source Code

    subroutine ensure_cache_structure(cache_dir, success)
        character(len=*), intent(in) :: cache_dir
        logical, intent(out) :: success
 character(len=:), allocatable :: builds_dir, modules_dir, executables_dir, metadata_dir

        ! Create main cache directory first
        call ensure_cache_dir(cache_dir, success)
        if (.not. success) return

        ! Create subdirectories using cross-platform paths
        builds_dir = join_path(trim(cache_dir), 'builds')
        modules_dir = join_path(trim(cache_dir), 'modules')
        executables_dir = join_path(trim(cache_dir), 'executables')
        metadata_dir = join_path(trim(cache_dir), 'metadata')

        ! Create each directory explicitly
        call mkdir(trim(builds_dir))
        call mkdir(trim(modules_dir))
        call mkdir(trim(executables_dir))
        call mkdir(trim(metadata_dir))

        ! Check if all directories were created successfully
        ! Use a more robust check that ensures they are directories, not files
        success = .true.
        if (exists(trim(builds_dir))) then
            block
                integer :: ios
                if (get_os_type() == OS_WINDOWS) then
                    call execute_command_line('dir "'//trim(escape_shell_arg(builds_dir))//'" >nul 2>&1', exitstat=ios)
                else
                    call execute_command_line('test -d "'//trim(escape_shell_arg(builds_dir))//'"', exitstat=ios)
                end if
                if (ios /= 0) success = .false.
            end block
        else
            success = .false.
        end if

        if (success .and. exists(trim(modules_dir))) then
            block
                integer :: ios
                if (get_os_type() == OS_WINDOWS) then
                    call execute_command_line('dir "'//trim(escape_shell_arg(modules_dir))//'" >nul 2>&1', exitstat=ios)
                else
                    call execute_command_line('test -d "'//trim(escape_shell_arg(modules_dir))//'"', exitstat=ios)
                end if
                if (ios /= 0) success = .false.
            end block
        else
            success = .false.
        end if

    end subroutine ensure_cache_structure