Skip to content

Commit c4afc51

Browse files
committed
Fix unzip and check for file existence
1 parent 57641e8 commit c4afc51

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/stdlib_io_zip.f90

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module stdlib_io_zip
88

99
character(*), parameter :: default_unzip_dir = temp_dir//'/unzipped_files'
1010
character(*), parameter :: zip_contents = default_unzip_dir//'/zip_contents.txt'
11-
character(*), parameter :: default_zip_dir = temp_dir//'.'
1211

1312
contains
1413

@@ -72,14 +71,20 @@ subroutine unzip(filename, outputdir, stat, msg)
7271
if (present(stat)) stat = 0
7372
run_stat = 0
7473

75-
call run('rm -rf '//default_unzip_dir, run_stat)
74+
if (.not. exists(filename)) then
75+
if (present(stat)) stat = 1
76+
if (present(msg)) msg = "File '"//filename//"' does not exist."
77+
return
78+
end if
79+
80+
call run('rm -rf '//output_dir, run_stat)
7681
if (run_stat /= 0) then
7782
if (present(stat)) stat = run_stat
78-
if (present(msg)) msg = "Error removing folder '"//default_unzip_dir//"'."
83+
if (present(msg)) msg = "Error removing folder '"//output_dir//"'."
7984
return
8085
end if
8186

82-
if (.not. exists(temp_dir)) then
87+
if (.not. present(outputdir) .and. .not. exists(temp_dir)) then
8388
call run('mkdir '//temp_dir, run_stat)
8489
if (run_stat /= 0) then
8590
if (present(stat)) stat = run_stat
@@ -88,8 +93,6 @@ subroutine unzip(filename, outputdir, stat, msg)
8893
end if
8994
end if
9095

91-
print *, 'hellohello'
92-
call execute_command_line('pwd')
9396
call run('unzip -q '//filename//' -d '//output_dir, run_stat)
9497
if (run_stat /= 0) then
9598
if (present(stat)) stat = run_stat

0 commit comments

Comments
 (0)