Skip to content

Commit 8eadf4a

Browse files
committed
Clean up code and delete file after use
1 parent 757e003 commit 8eadf4a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/fpm/cmd/publish.f90

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module fpm_cmd_publish
88
use fpm_model, only: fpm_model_t
99
use fpm_error, only: error_t, fpm_stop
1010
use fpm_versioning, only: version_t
11-
use fpm_filesystem, only: exists, join_path, get_temp_filename
11+
use fpm_filesystem, only: exists, join_path, get_temp_filename, delete_file
1212
use fpm_git, only: git_archive
1313
use fpm_downloader, only: downloader_t
1414
use fpm_strings, only: string_t
@@ -64,34 +64,37 @@ subroutine cmd_publish(settings)
6464
end if
6565
end do
6666

67+
tmp_file = get_temp_filename()
68+
call git_archive('.', tmp_file, error)
69+
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Archive error: '//error%message)
70+
6771
upload_data = [ &
68-
string_t('package_name="'//package%name//'"'), &
69-
string_t('package_license="'//package%license//'"'), &
70-
string_t('package_version="'//version%s()//'"') &
71-
& ]
72+
& string_t('package_name="'//package%name//'"'), &
73+
& string_t('package_license="'//package%license//'"'), &
74+
& string_t('package_version="'//version%s()//'"'), &
75+
& string_t('tarball=@"'//tmp_file//'"') &
76+
& ]
7277

7378
if (allocated(settings%token)) upload_data = [upload_data, string_t('upload_token="'//settings%token//'"')]
7479

75-
tmp_file = get_temp_filename()
76-
call git_archive('.', tmp_file, error)
77-
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Pack error: '//error%message)
78-
upload_data = [upload_data, string_t('tarball=@"'//tmp_file//'"')]
79-
8080
if (settings%show_upload_data) then
8181
do i = 1, size(upload_data)
8282
print *, upload_data(i)%s
8383
end do
84-
return
84+
call delete_file(tmp_file); return
8585
end if
8686

8787
! Make sure a token is provided for publishing.
8888
if (allocated(settings%token)) then
89-
if (settings%token == '') call fpm_stop(1, 'No token provided.')
89+
if (settings%token == '') then
90+
call delete_file(tmp_file); call fpm_stop(1, 'No token provided.')
91+
end if
9092
else
91-
call fpm_stop(1, 'No token provided.')
93+
call delete_file(tmp_file); call fpm_stop(1, 'No token provided.')
9294
end if
9395

9496
call downloader%upload_form(official_registry_base_url//'/packages', upload_data, error)
97+
call delete_file(tmp_file)
9598
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Upload error: '//error%message)
9699
end
97100
end

src/fpm/git.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ subroutine git_archive(source, destination, error)
328328
call fatal_error(error, "Cannot find a suitable archive format for 'git archive'."); return
329329
end if
330330

331-
call execute_command_line('git archive HEAD --format='//archive_format//' -o '// destination, exitstat=stat)
331+
call execute_command_line('git archive HEAD --format='//archive_format//' -o '//destination, exitstat=stat)
332332
if (stat /= 0) then
333333
call fatal_error(error, "Error packing '"//source//"'."); return
334334
end if

0 commit comments

Comments
 (0)