@@ -58,7 +58,8 @@ module fpm_dependency
5858 use , intrinsic :: iso_fortran_env, only: output_unit
5959 use fpm_environment, only: get_os_type, OS_WINDOWS, os_is_unix
6060 use fpm_error, only: error_t, fatal_error
61- use fpm_filesystem, only: exists, join_path, mkdir, canon_path, windows_path, list_files, is_dir, basename, os_delete_dir
61+ use fpm_filesystem, only: exists, join_path, mkdir, canon_path, windows_path, list_files, is_dir, basename, &
62+ os_delete_dir, get_temp_filename
6263 use fpm_git, only: git_target_revision, git_target_default, git_revision, operator (==)
6364 use fpm_manifest, only: package_config_t, dependency_config_t, get_package_data
6465 use fpm_manifest_dependency, only: manifest_has_changed
@@ -637,7 +638,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
637638 ! > Downloader instance.
638639 class(downloader_t), optional , intent (in ) :: downloader_
639640
640- character (:), allocatable :: cache_path, target_url, tmp_pkg_path, tmp_pkg_file
641+ character (:), allocatable :: cache_path, target_url, tmp_file
641642 type (version_t) :: version
642643 integer :: stat, unit
643644 type (json_object) :: json
@@ -666,18 +667,15 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
666667 end if
667668 end if
668669
669- ! Define location of the temporary folder and file.
670- tmp_pkg_path = join_path(global_settings% path_to_config_folder, ' tmp' )
671- if (.not. exists(tmp_pkg_path)) call mkdir(tmp_pkg_path)
672- tmp_pkg_file = join_path(tmp_pkg_path, ' package_data.tmp' )
673- open (newunit= unit, file= tmp_pkg_file, action= ' readwrite' , iostat= stat)
670+ tmp_file = get_temp_filename()
671+ open (newunit= unit, file= tmp_file, action= ' readwrite' , iostat= stat)
674672 if (stat /= 0 ) then
675673 call fatal_error(error, " Error creating temporary file for downloading package '" // self% name// " '." ); return
676674 end if
677675
678676 ! Include namespace and package name in the target url and download package data.
679677 target_url = global_settings% registry_settings% url// ' /packages/' // self% namespace// ' /' // self% name
680- call downloader% get_pkg_data(target_url, self% requested_version, tmp_pkg_file , json, error)
678+ call downloader% get_pkg_data(target_url, self% requested_version, tmp_file , json, error)
681679 close (unit, status= ' delete' )
682680 if (allocated (error)) return
683681
@@ -686,7 +684,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
686684 if (allocated (error)) return
687685
688686 ! Open new tmp file for downloading the actual package.
689- open (newunit= unit, file= tmp_pkg_file , action= ' readwrite' , iostat= stat)
687+ open (newunit= unit, file= tmp_file , action= ' readwrite' , iostat= stat)
690688 if (stat /= 0 ) then
691689 call fatal_error(error, " Error creating temporary file for downloading package '" // self% name// " '." ); return
692690 end if
@@ -697,13 +695,13 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
697695 if (is_dir(cache_path)) call os_delete_dir(os_is_unix(), cache_path)
698696 call mkdir(cache_path)
699697
700- call downloader% get_file(target_url, tmp_pkg_file , error)
698+ call downloader% get_file(target_url, tmp_file , error)
701699 if (allocated (error)) then
702700 close (unit, status= ' delete' ); return
703701 end if
704702
705703 ! Unpack the downloaded package to the final location.
706- call downloader% unpack (tmp_pkg_file , cache_path, error)
704+ call downloader% unpack (tmp_file , cache_path, error)
707705 close (unit, status= ' delete' )
708706 if (allocated (error)) return
709707 end if
0 commit comments