@@ -953,22 +953,25 @@ subroutine make_directory_all(path, err)
953
953
character (len=* ), intent (in ) :: path
954
954
type (state_type), optional , intent (out ) :: err
955
955
956
- integer :: code, i, indx
956
+ character (:), allocatable :: trim_path
957
+ integer :: i, indx
957
958
type (state_type) :: err0
958
959
character (len= 1 ) :: sep
959
- logical :: is_dir
960
+ logical :: is_dir, check_is_dir
960
961
962
+ trim_path = trim (path)
961
963
sep = path_sep()
962
964
i = 1
963
- indx = find(path, sep, i)
965
+ indx = find(trim_path, sep, i)
966
+ check_is_dir = .true.
964
967
965
968
do
966
969
! Base case to exit the loop
967
- if (indx == 0 .or. indx == len (trim (path) )) then
968
- is_dir = is_directory(path )
970
+ if (indx == 0 .or. indx == len (trim_path )) then
971
+ is_dir = is_directory(trim_path )
969
972
970
973
if (.not. is_dir) then
971
- call make_directory(path , err0)
974
+ call make_directory(trim_path , err0)
972
975
973
976
if (err0% error()) then
974
977
call err0% handle(err)
@@ -978,19 +981,24 @@ subroutine make_directory_all(path, err)
978
981
end if
979
982
end if
980
983
981
- is_dir = is_directory(path(1 :indx))
984
+ if (check_is_dir) then
985
+ is_dir = is_directory(trim_path(1 :indx))
986
+ end if
982
987
983
988
if (.not. is_dir) then
984
- call make_directory(path(1 :indx), err0)
989
+ ! no need for further `is_dir` checks
990
+ ! all paths going forward need to be created
991
+ check_is_dir = .false.
992
+ call make_directory(trim_path(1 :indx), err0)
985
993
986
994
if (err0% error()) then
987
995
call err0% handle(err)
988
996
return
989
997
end if
990
998
end if
991
999
992
- i = i + 1
993
- indx = find(path , sep, i)
1000
+ i = i + 1 ! the next occurence of `sep`
1001
+ indx = find(trim_path , sep, i)
994
1002
end do
995
1003
end subroutine make_directory_all
996
1004
0 commit comments