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