Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not store temporary data in .local #900

Merged
merged 1 commit into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/fpm/dependency.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ module fpm_dependency
use, intrinsic :: iso_fortran_env, only: output_unit
use fpm_environment, only: get_os_type, OS_WINDOWS, os_is_unix
use fpm_error, only: error_t, fatal_error
use fpm_filesystem, only: exists, join_path, mkdir, canon_path, windows_path, list_files, is_dir, basename, os_delete_dir
use fpm_filesystem, only: exists, join_path, mkdir, canon_path, windows_path, list_files, is_dir, basename, &
os_delete_dir, get_temp_filename
use fpm_git, only: git_target_revision, git_target_default, git_revision, operator(==)
use fpm_manifest, only: package_config_t, dependency_config_t, get_package_data
use fpm_manifest_dependency, only: manifest_has_changed
Expand Down Expand Up @@ -637,7 +638,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
!> Downloader instance.
class(downloader_t), optional, intent(in) :: downloader_

character(:), allocatable :: cache_path, target_url, tmp_pkg_path, tmp_pkg_file
character(:), allocatable :: cache_path, target_url, tmp_file
type(version_t) :: version
integer :: stat, unit
type(json_object) :: json
Expand Down Expand Up @@ -666,18 +667,15 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
end if
end if

! Define location of the temporary folder and file.
tmp_pkg_path = join_path(global_settings%path_to_config_folder, 'tmp')
if (.not. exists(tmp_pkg_path)) call mkdir(tmp_pkg_path)
tmp_pkg_file = join_path(tmp_pkg_path, 'package_data.tmp')
open (newunit=unit, file=tmp_pkg_file, action='readwrite', iostat=stat)
tmp_file = get_temp_filename()
open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat)
if (stat /= 0) then
call fatal_error(error, "Error creating temporary file for downloading package '"//self%name//"'."); return
end if

! Include namespace and package name in the target url and download package data.
target_url = global_settings%registry_settings%url//'/packages/'//self%namespace//'/'//self%name
call downloader%get_pkg_data(target_url, self%requested_version, tmp_pkg_file, json, error)
call downloader%get_pkg_data(target_url, self%requested_version, tmp_file, json, error)
close (unit, status='delete')
if (allocated(error)) return

Expand All @@ -686,7 +684,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
if (allocated(error)) return

! Open new tmp file for downloading the actual package.
open (newunit=unit, file=tmp_pkg_file, action='readwrite', iostat=stat)
open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat)
if (stat /= 0) then
call fatal_error(error, "Error creating temporary file for downloading package '"//self%name//"'."); return
end if
Expand All @@ -697,13 +695,13 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade
if (is_dir(cache_path)) call os_delete_dir(os_is_unix(), cache_path)
call mkdir(cache_path)

call downloader%get_file(target_url, tmp_pkg_file, error)
call downloader%get_file(target_url, tmp_file, error)
if (allocated(error)) then
close (unit, status='delete'); return
end if

! Unpack the downloaded package to the final location.
call downloader%unpack(tmp_pkg_file, cache_path, error)
call downloader%unpack(tmp_file, cache_path, error)
close (unit, status='delete')
if (allocated(error)) return
end if
Expand Down