Skip to content

Commit e92d9c9

Browse files
authored
Merge pull request #208 from LKedward/filesystem-fixes
Minor fixes: to list_files and mkdir in fpm_filesystem
2 parents ad9ebad + f319d32 commit e92d9c9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fpm/src/fpm_filesystem.f90

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ subroutine mkdir(dir)
215215
character(len=*), intent(in) :: dir
216216
integer :: stat
217217

218+
if (is_dir(dir)) return
219+
218220
select case (get_os_type())
219221
case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
220222
call execute_command_line('mkdir -p ' // dir, exitstat=stat)
@@ -233,6 +235,11 @@ end subroutine mkdir
233235

234236

235237
recursive subroutine list_files(dir, files, recurse)
238+
! Get file & directory names in directory `dir`.
239+
!
240+
! - File/directory names return are relative to cwd, ie. preprended with `dir`
241+
! - Includes files starting with `.` except current directory and parent directory
242+
!
236243
character(len=*), intent(in) :: dir
237244
type(string_t), allocatable, intent(out) :: files(:)
238245
logical, intent(in), optional :: recurse
@@ -242,8 +249,7 @@ recursive subroutine list_files(dir, files, recurse)
242249
type(string_t), allocatable :: dir_files(:)
243250
type(string_t), allocatable :: sub_dir_files(:)
244251

245-
! Using `inquire` / exists on directories works with gfortran, but not ifort
246-
if (.not. exists(dir)) then
252+
if (.not. is_dir(dir)) then
247253
allocate (files(0))
248254
return
249255
end if
@@ -252,7 +258,7 @@ recursive subroutine list_files(dir, files, recurse)
252258

253259
select case (get_os_type())
254260
case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
255-
call execute_command_line('ls ' // dir // ' > ' // temp_file, &
261+
call execute_command_line('ls -A ' // dir // ' > ' // temp_file, &
256262
exitstat=stat)
257263
case (OS_WINDOWS)
258264
call execute_command_line('dir /b ' // windows_path(dir) // ' > ' // temp_file, &

0 commit comments

Comments
 (0)